module Chione::MethodUtilities

A collection of methods for declaring other methods.

class MyClass
    extend Chione::MethodUtilities

    singleton_attr_accessor :types
    singleton_method_alias :kinds, :types
end

MyClass.types = [ :pheno, :proto, :stereo ]
MyClass.kinds # => [:pheno, :proto, :stereo]

Public Instance Methods

attr_predicate( attrname ) click to toggle source

Create a reader in the form of a predicate for the given attrname.

# File lib/chione/mixins.rb, line 72
def attr_predicate( attrname )
        attrname = attrname.to_s.chomp( '?' )
        define_method( "#{attrname}?" ) do
                instance_variable_get( "@#{attrname}" ) ? true : false
        end
end
attr_predicate_accessor( attrname ) click to toggle source

Create a reader in the form of a predicate for the given attrname as well as a regular writer method.

# File lib/chione/mixins.rb, line 82
def attr_predicate_accessor( attrname )
        attrname = attrname.to_s.chomp( '?' )
        attr_writer( attrname )
        attr_predicate( attrname )
end
singleton_attr_accessor( *symbols ) click to toggle source

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

# File lib/chione/mixins.rb, line 51
def singleton_attr_accessor( *symbols )
        symbols.each do |sym|
                singleton_class.__send__( :attr_accessor, sym )
        end
end
singleton_attr_reader( *symbols ) click to toggle source

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).

# File lib/chione/mixins.rb, line 26
def singleton_attr_reader( *symbols )
        singleton_class.instance_exec( symbols ) do |attrs|
                attr_reader( *attrs )
        end
end
singleton_attr_writer( *symbols ) click to toggle source

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

# File lib/chione/mixins.rb, line 42
def singleton_attr_writer( *symbols )
        singleton_class.instance_exec( symbols ) do |attrs|
                attr_writer( *attrs )
        end
end
singleton_method_alias( newname, original ) click to toggle source

Creates an alias for the original method named newname.

# File lib/chione/mixins.rb, line 66
def singleton_method_alias( newname, original )
        singleton_class.__send__( :alias_method, newname, original )
end
singleton_predicate_accessor( *symbols ) click to toggle source

Create predicate methods and writers that allow assignment to the attributes of the singleton of the declaring object that correspond to the specified symbols.

# File lib/chione/mixins.rb, line 60
def singleton_predicate_accessor( *symbols )
        singleton_class.extend( Chione::MethodUtilities )
        singleton_class.attr_predicate_accessor( *symbols )
end
singleton_predicate_reader( *symbols ) click to toggle source

Create instance variables and corresponding methods that return true or false values for each of the specified symbols in the singleton of the declaring object.

# File lib/chione/mixins.rb, line 35
def singleton_predicate_reader( *symbols )
        singleton_class.extend( Chione::MethodUtilities )
        singleton_class.attr_predicate( *symbols )
end