Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Using &block as constructor
# &block constructors
# From http://www.deploymentzone.com/2011/06/23/block-constructors
# If you need a behavior like this in your class:
Person.new do |p|
p.first_name = "John"
p.last_name = "Brown"
p.dob = Date.parse("5/9/1800")
end
# You can achieve it with this snippet:
class Person
attr_accessor :first_name, :last_name, :dob
def initialize
yield self if block_given?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.