Skip to content

Instantly share code, notes, and snippets.

@eviltrout
Created May 26, 2009 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eviltrout/118062 to your computer and use it in GitHub Desktop.
Save eviltrout/118062 to your computer and use it in GitHub Desktop.
def make_new(obj, hash)
new_ob = type.new
# Two approaches - 1st: You can use the array notation [] on an activerecord to use it like a hash
hash.each do {|key, value| new_ob[key] = value }
# Or you can send to the method using period:
hash.each do {|key, value| new_ob.send("#{key.to_s}=", value) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment