Module: Sequel::Metaprogramming

Included in:
Database, Dataset, Model
Defined in:
lib/sequel/extensions/meta_def.rb

Overview

Contains meta_def method for adding methods to objects via blocks. Only recommended for backwards compatibility with existing code.

Instance Method Summary collapse

Instance Method Details

#meta_def(name, &block) ⇒ Object

Define a method with the given name and block body on the receiver.

ds = DB[:items]
ds.meta_def(:x){42}
ds.x # => 42


22
23
24
# File 'lib/sequel/extensions/meta_def.rb', line 22

def meta_def(name, &block)
  (class << self; self end).send(:define_method, name, &block)
end