Class: Bio::REBASE::DynamicMethod_Hash

Inherits:
Hash show all
Defined in:
lib/bio/db/rebase.rb

Overview

:nodoc:

Direct Known Subclasses

EnzymeEntry

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object

Define a writer or reader

  • Allows hash= to be accessed like hash.key=

  • Allows hash to be accessed like hash.key



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/bio/db/rebase.rb', line 117

def method_missing(method_id, *args)
  k = self.class
  if method_id.to_s[-1].chr == '='
    k.class_eval do
      define_method(method_id) { |s| self[ method_id.to_s[0..-2].to_sym ] = s }
    end
    k.instance_method(method_id).bind(self).call(args[0])
  else
    k.class_eval do
      define_method(method_id) { self[method_id] }
    end
    k.instance_method(method_id).bind(self).call
  end
end