Skip to content

Instantly share code, notes, and snippets.

@44uk
Created August 18, 2012 06:00
Show Gist options
  • Save 44uk/3384755 to your computer and use it in GitHub Desktop.
Save 44uk/3384755 to your computer and use it in GitHub Desktop.
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