Skip to content

Instantly share code, notes, and snippets.

@fcoury
Created April 18, 2009 02:53
Show Gist options
  • Save fcoury/97401 to your computer and use it in GitHub Desktop.
Save fcoury/97401 to your computer and use it in GitHub Desktop.
require 'ostruct'
def objectify(val)
if val.is_a?(Hash)
result = {}
val.each_pair { |k,v| result[k] = objectify(v) }
result = OpenStruct.new(result)
elsif val.is_a?(Array)
result = []
val.each { |v| result << objectify(v) }
else
result = val
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment