Skip to content

Instantly share code, notes, and snippets.

@44uk
Created August 18, 2012 06:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Ruby Class Initialize with attributes
class Hoe
# attr_accessor
def initialize(attributes = nil)
assign_attributes(attributes) if attributes
yield self if block_given?
end
def assign_attributes(new_attributes)
new_attributes.each do |k, v|
send("#{k.to_s}=", v) if respond_to?("#{k.to_s}=")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment