Module: Inversion::MethodUtilities

Included in:
CLI, Template::Tag
Defined in:
lib/inversion/mixins.rb

Overview

A collection of methods for declaring other methods.

class MyClass
    include Inversion::MethodUtilities

    singleton_attr_accessor :types
end

MyClass.types = [ :pheno, :proto, :stereo ]

Instance Method Summary collapse

Instance Method Details

#singleton_attr_accessor(*symbols) ⇒ Object

Creates readers and writers that allow assignment to the attributes of the singleton of the declaring object that correspond to the specified ‘symbols`.



217
218
219
220
221
# File 'lib/inversion/mixins.rb', line 217

def singleton_attr_accessor( *symbols )
  symbols.each do |sym|
    singleton_class.__send__( :attr_accessor, sym )
  end
end

#singleton_attr_reader(*symbols) ⇒ Object

Creates instance variables and corresponding methods that return their values for each of the specified ‘symbols` in the singleton of the declaring object (e.g., class instance variables and methods if declared in a Class).



200
201
202
203
204
# File 'lib/inversion/mixins.rb', line 200

def singleton_attr_reader( *symbols )
  symbols.each do |sym|
    singleton_class.__send__( :attr_reader, sym )
  end
end

#singleton_attr_writer(*symbols) ⇒ Object

Creates methods that allow assignment to the attributes of the singleton of the declaring object that correspond to the specified ‘symbols`.



208
209
210
211
212
# File 'lib/inversion/mixins.rb', line 208

def singleton_attr_writer( *symbols )
  symbols.each do |sym|
    singleton_class.__send__( :attr_writer, sym )
  end
end