Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

convert string to hash ruby

hash_as_string = 
	"{"0"=>{"answer"=>"1", "value"=>"No"}, 
    "1"=>{"answer"=>"2", "value"=>"Yes"}, 
    "2"=>{"answer"=>"3", "value"=>"No"}, 
    "3"=>{"answer"=>"4", "value"=>"1"}, 
    "4"=>{"value"=>"2"}, "5"=>{"value"=>"3"}, 
    "6"=>{"value"=>"4"}}"
JSON.parse hash_as_string.gsub('=>', ':')
Comment

string to hash ruby

pairs = string.scan(/(w+):s+([^;]+)/).map { |k,v| [k.to_sym, v.strip] }
result = Hash[pairs]
Comment

PREVIOUS NEXT
Code Example
Ruby :: array ruby taking 3 last value 
Ruby :: ruby hash transform values 
Ruby :: How can I rename a database column in a Ruby on Rails migration? 
Ruby :: hello world in ruby 
Ruby :: rails migration polymorphic references 
Ruby :: ruby file write 
Ruby :: ruby attr_accessor multiple variables 
Ruby :: ruby capitalize first character of sentence 
Ruby :: ruby regexp match all 
Ruby :: http request ruby 
Ruby :: how to format date and time in rails 
Ruby :: rails validate presence 
Ruby :: rails get asset path from console 
Ruby :: rails array sort 
Ruby :: ruby reverse string 
Ruby :: Rails.root 
Ruby :: random datetime ruby 
Ruby :: rails faker 
Ruby :: params except rails 
Ruby :: rails get random record 
Ruby :: ruby ternary operator 
Ruby :: how to upload a file in capybara spec 
Ruby :: ruby is method defined 
Ruby :: ruby remove nil element in array 
Ruby :: httparty headers 
Ruby :: deliver_later not sending mail in sidekiq in rails 
Ruby :: # Create empty 2 dimensional array 
Ruby :: rails check log level of application 
Ruby :: Range extraction: convert a comma separated list of integers into range format 
Ruby :: does destroy retrurn in ruby 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =