Created
March 10, 2012 15:44
-
-
Save zakgrant/2011830 to your computer and use it in GitHub Desktop.
Alias'd Instantiation
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 Person | |
attr_accessor :first_name, :surname | |
@first_name = 'zak' | |
@surname = 'grant' | |
class << self | |
def new(options={}) | |
Person.new options | |
end | |
def method_missing(method, *args, &block) | |
return super unless new.respond_to? method | |
new.send method, *args, &block | |
end | |
end | |
def full_name | |
"#{@first_name} #{@surname}" | |
end | |
end | |
puts "#{Person.full_name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment