joshsusser (owner)

Revisions

gist: 153758 Download_button fork
public
Public Clone URL: git://gist.github.com/153758.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  ### meta magic boolean attributes
  def self.attr_boolean(attr_name)
    class_eval(<<-CODE, __FILE__, __LINE__)
def #{attr_name}=(#{attr_name})
@#{attr_name} = !!(/^1|true$/i =~ #{attr_name}) # yes, we need a boolean
end
 
def #{attr_name}
@#{attr_name}
end
alias_method :#{attr_name}?, :#{attr_name}
CODE
  end
 
  attr_boolean :is_awesome
  attr_boolean :has_mutant_powers