Created
August 18, 2012 06:00
-
-
Save 44uk/3384755 to your computer and use it in GitHub Desktop.
Ruby Class Initialize with attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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