Skip to content

Instantly share code, notes, and snippets.

@nmenag
Created January 25, 2015 02:01
Show Gist options
  • Save nmenag/fd253848d3fdcc8a54f1 to your computer and use it in GitHub Desktop.
Save nmenag/fd253848d3fdcc8a54f1 to your computer and use it in GitHub Desktop.
Creación de métodos dinámicos.
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
@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