Module: TT::BooleanAttributes

Included in:
Profiler
Defined in:
TT_Lib2/boolean_attributes.rb

Overview

Examples:

class Foo
  extend TT::BooleanAttributes
  battr_accessor :bar
end

Since:

  • 2.7.0

Instance Method Summary collapse

Instance Method Details

#battr(symbol, writable = false) ⇒ Object

Since:

  • 2.7.0



20
21
22
23
24
25
26
27
# File 'TT_Lib2/boolean_attributes.rb', line 20

def battr( symbol, writable = false )
  self.class_eval {
    attr( symbol, writable )
    question = "#{symbol}?".to_sym
    alias_method( question, symbol )
    remove_method( symbol )
  }
end

#battr_accessor(*args) ⇒ Object

Since:

  • 2.7.0



30
31
32
33
34
35
36
37
38
39
# File 'TT_Lib2/boolean_attributes.rb', line 30

def battr_accessor( *args )
  self.class_eval {
    attr_accessor( *args )
    for attribute in args
      question = "#{attribute}?".to_sym
      alias_method( question, attribute )
      remove_method( attribute )
    end
  }
end

#battr_reader(*args) ⇒ Object

Since:

  • 2.7.0



42
43
44
45
46
47
48
49
50
51
# File 'TT_Lib2/boolean_attributes.rb', line 42

def battr_reader( *args )
  self.class_eval {
    attr_reader( *args )
    for attribute in args
      question = "#{attribute}?".to_sym
      alias_method( question, attribute )
      remove_method( attribute )
    end
  }
end