Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rdf_helpers.rb

Instance Method Summary collapse

Instance Method Details

#bool_accessor(*syms) ⇒ Object

Adds boolean accessor to a class (e.g. person.male?)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_rdf_helpers.rb', line 9

def bool_accessor *syms
  syms.flatten.each do |sym|
    next unless sym.is_a?(Symbol)
    class_eval(<<-EOS, __FILE__, __LINE__)
      unless defined? @#{sym}
        @#{sym} = nil
      end

      def #{sym}=(val)
        @#{sym} = val ? true : false
      end

      def #{sym}?
        @#{sym} ? true : false
      end
    EOS
  end
end