Created
January 25, 2015 02:01
-
-
Save nmenag/fd253848d3fdcc8a54f1 to your computer and use it in GitHub Desktop.
Creación de métodos dinámicos.
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 User | |
STATUS = {active: "Active", inactive: "Inactive", invited:"Invited"} | |
STATUS.each_with_index do |(meth, value)| | |
define_method("is_#{meth}?"){status == value} | |
end | |
def initialize(name, email, password, status) | |
@name = name | |
@email = email | |
@password = password | |
@status = status | |
end | |
def name | |
@name | |
end | |
def email | |
end | |
def password | |
@password | |
end | |
def status | |
@status | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment