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)


92
93
94
# File 'lib/sequel_core/core_ext.rb', line 92

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)


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

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

#meta_def(name, &block) ⇒ Object

Add methods to the object’s metaclass



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

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



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

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

#metaclassObject

The hidden singleton lurks behind everyone



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

def metaclass
  class << self
    self
  end 
end