Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/fp_rb.rb,
lib/fn_reader.rb
Instance Method Summary collapse
-
#fn_reader(*syms) ⇒ Object
Stripped down version of ActiveSupport’s mattr_reader (don’t want Rails dependencies).
Instance Method Details
#fn_reader(*syms) ⇒ Object
Stripped down version of ActiveSupport’s mattr_reader (don’t want Rails dependencies)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fp_rb.rb', line 5 def fn_reader(*syms) syms.each do |sym| raise StandardError.new("invalid attribute name: #{sym}") unless (sym =~ /\A[_A-Za-z]\w*\z/) class_eval(<<-EOS, __FILE__, __LINE__ + 1) @@#{sym} = nil unless defined? @@#{sym} def self.#{sym} @@#{sym} end EOS class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{sym} @@#{sym} end EOS end end |