Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Using &block as constructor
# &block constructors
# From
# If you need a behavior like this in your class: do |p|
p.first_name = "John"
p.last_name = "Brown"
p.dob = Date.parse("5/9/1800")
# You can achieve it with this snippet:
class Person
attr_accessor :first_name, :last_name, :dob
def initialize
yield self if block_given?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment