Class: Object

Inherits:
BasicObject
Defined in:
lib/sequel_core/core_ext.rb

Overview

Helpers from Metaid and a bit more

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Objects are blank if they respond true to empty?

Returns:

  • (Boolean)


106
107
108
# File 'lib/sequel_core/core_ext.rb', line 106

def blank?
  respond_to?(:empty?) && empty?
end

#is_one_of?(*classes) ⇒ Boolean

Returns true if the object is an instance of one of the classes

Returns:

  • (Boolean)


111
112
113
# File 'lib/sequel_core/core_ext.rb', line 111

def is_one_of?(*classes)
  !!classes.find{|c| is_a?(c)}
end

#meta_def(name, &block) ⇒ Object

Add methods to the object’s metaclass



116
117
118
# File 'lib/sequel_core/core_ext.rb', line 116

def meta_def(name, &block)
  meta_eval{define_method(name, &block)}
end

#meta_eval(&block) ⇒ Object

Evaluate the block in the context of the object’s metaclass



121
122
123
# File 'lib/sequel_core/core_ext.rb', line 121

def meta_eval(&block)
  metaclass.instance_eval(&block)
end

#metaclassObject

The hidden singleton lurks behind everyone



126
127
128
129
130
# File 'lib/sequel_core/core_ext.rb', line 126

def metaclass
  class << self
    self
  end 
end