module AttrReadonly
module Methodic @author Romain GEORGES <romain@ultragreen.net> @see www.ultragreen.net/projects/attr_reader @version 1.0.0 @note this module include a method to be mix in Module
(Class)
Constants
- VERSION
current version of
attr_readonly
Public Instance Methods
attr_readonly(*syms)
click to toggle source
pretty accessor for specifying mandatories options @param [*Symbol] syms a list of symbols defining accessors to add @return [Array] Array of symbols methods name (accessors) created @example usage
require 'attr_readonly' class Test attr_readonly :foo def initialize(foo: '') @foo = :foo end end
# File lib/attr_readonly.rb, line 36 def attr_readonly *syms syms.each do |method| define_method(method){ return self.instance_variable_get("@#{method.to_s}").dup.freeze } end end