Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/as_readonly/core_ext/module.rb

Instance Method Summary collapse

Instance Method Details

#attr_readonly(*attributes) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/as_readonly/core_ext/module.rb', line 4

def attr_readonly(*attributes)
  attributes.each do |attr|
    module_eval <<-"end_eval", __FILE__, __LINE__
      def #{attr}
        @_#{attr}_as_readonly ||= begin
          @#{attr} ? @#{attr}.as_readonly : @#{attr}
        end
      end
    end_eval
  end
end