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)


98
99
100
# File 'lib/sequel_core/core_ext.rb', line 98

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)


103
104
105
# File 'lib/sequel_core/core_ext.rb', line 103

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

#meta_def(name, &block) ⇒ Object

Add methods to the object’s metaclass



108
109
110
# File 'lib/sequel_core/core_ext.rb', line 108

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



113
114
115
# File 'lib/sequel_core/core_ext.rb', line 113

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

#metaclassObject

The hidden singleton lurks behind everyone



118
119
120
121
122
# File 'lib/sequel_core/core_ext.rb', line 118

def metaclass
  class << self
    self
  end 
end