Chione::

MethodUtilities module

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 )

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

   # File lib/chione/mixins.rb
72 def attr_predicate( attrname )
73     attrname = attrname.to_s.chomp( '?' )
74     define_method( "#{attrname}?" ) do
75         instance_variable_get( "@#{attrname}" ) ? true : false
76     end
77 end
attr_predicate_accessor( attrname )

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
82 def attr_predicate_accessor( attrname )
83     attrname = attrname.to_s.chomp( '?' )
84     attr_writer( attrname )
85     attr_predicate( attrname )
86 end
singleton_attr_accessor( *symbols )

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
51 def singleton_attr_accessor( *symbols )
52     symbols.each do |sym|
53         singleton_class.__send__( :attr_accessor, sym )
54     end
55 end
singleton_attr_reader( *symbols )

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
26 def singleton_attr_reader( *symbols )
27     singleton_class.instance_exec( symbols ) do |attrs|
28         attr_reader( *attrs )
29     end
30 end
singleton_attr_writer( *symbols )

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
42 def singleton_attr_writer( *symbols )
43     singleton_class.instance_exec( symbols ) do |attrs|
44         attr_writer( *attrs )
45     end
46 end
singleton_method_alias( newname, original )

Creates an alias for the original method named newname.

   # File lib/chione/mixins.rb
66 def singleton_method_alias( newname, original )
67     singleton_class.__send__( :alias_method, newname, original )
68 end
singleton_predicate_accessor( *symbols )

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
60 def singleton_predicate_accessor( *symbols )
61     singleton_class.extend( Chione::MethodUtilities )
62     singleton_class.attr_predicate_accessor( *symbols )
63 end
singleton_predicate_reader( *symbols )

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
35 def singleton_predicate_reader( *symbols )
36     singleton_class.extend( Chione::MethodUtilities )
37     singleton_class.attr_predicate( *symbols )
38 end