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 :: transfer parameters in link_to rails 
Ruby :: ruby array shift 
Ruby :: how to destroy a generate in rails 
Ruby :: rails image disappears after showing 
Ruby :: dynamic database connection in rails 
Ruby :: While executing gem 
Ruby :: ruby on rails scaffold generator example with belongs to relationship 
Ruby :: run ruby script 
Ruby :: ruby abs function programming 
Ruby :: ruby get ascii value of character 
Ruby :: rails g controller with actions 
Ruby :: ruby for programmers 
Ruby :: rails migration column types 
Ruby :: how to unloack user devise rails 
Ruby :: find subset of two hashes in ruby 
Ruby :: devise signout via get with https 
Ruby :: devise valid password 
Ruby :: ruby on rails collapse array 
Ruby :: update_all 
Ruby :: apple calendar gem in rails 
Ruby :: add extension in ruby tempfile object 
Ruby :: hello world ruby 
R :: how to add random numbers randomly in a dataframe in r 
R :: r range with step 
R :: how to import csv file in r 
R :: comment in r 
R :: how to itterate through a character in r 
R :: convert a datetime to date r 
R :: How to use par() in R 
R :: color code in R 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =