LoginSignup
1
1

More than 5 years have passed since last update.

配列の作成・ハッシュの作成の備忘録

Last updated at Posted at 2015-03-12

2015/03/13 修正しました。

require 'rubygems'
require 'json'

print "プロダクトID?:"
project = gets.chomp
print "トラッカーID?:"
tracker = gets.chomp
print "タイトル?:"
subject = gets.chomp
print "内容?:"
desc = gets.chomp

#ハッシュ
issue = {}
issue[:project_id] = project
issue[:tracker_id] = tracker
issue[:subject] = subject
issue[:description] = desc
data = { :issue => issue }

puts data.class
puts "================================================================="
  p data
puts "================================================================="

#配列
issue = []
project_id = project
tracker_id = tracker
subject = subject
description = desc
issue <<  {"projcect_id" => project_id , "tracker_id" => tracker_id , "subject" => subject , "description" => description}

puts issue.class
puts "================================================================="
  p issue
puts "================================================================="


#おまけ JSON
puts "おまけJSON"
puts data.to_json
puts
puts issue.to_json


$ ruby hash.rb
プロダクトID?:1
トラッカーID?:4
タイトル?:hogehoge
内容?:mogemoge
Hash
=================================================================
{:issue=>{:project_id=>"1", :tracker_id=>"4", :subject=>"hogehoge", :description=>"mogemoge"}}
=================================================================
Array
=================================================================
[{"projcect_id"=>"1", "tracker_id"=>"4", "subject"=>"hogehoge", "description"=>"mogemoge"}]
=================================================================
おまけJSON
{"issue":{"project_id":"1","tracker_id":"4","subject":"hogehoge","description":"mogemoge"}}

[{"projcect_id":"1","tracker_id":"4","subject":"hogehoge","description":"mogemoge"}]

気をつけよう(´ω`)‥トホー

1
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1