Class: Object

Inherits:
BasicObject
Defined in:
lib/rucola/test_helper.rb,
lib/rucola/rucola_support/core_ext/ruby/object.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended_class_methodsObject

Returns an array of all the class methods that were added by extending the class.

class FooBar; end

module Baz
  def a_new_class_method; end
end
FooBar.extend(Baz)

FooBar.extended_class_methods # => ['a_new_class_method']


20
21
22
# File 'lib/rucola/rucola_support/core_ext/ruby/object.rb', line 20

def self.extended_class_methods
  metaclass.included_modules.map { |mod| mod.instance_methods }.flatten.uniq
end

.metaclassObject

Returns a class’s metaclass.

class FooBar; end
p FooBar.metaclass # => #<Class:FooBar>


6
7
8
# File 'lib/rucola/rucola_support/core_ext/ruby/object.rb', line 6

def self.metaclass
  class << self; self; end
end

.original_class_methodsObject

Returns an array of all the class methods that were defined in only this class, so without class methods from any of it’s superclasses or from extending it.



44
45
46
# File 'lib/rucola/rucola_support/core_ext/ruby/object.rb', line 44

def self.original_class_methods
  own_class_methods - extended_class_methods
end

.own_class_methodsObject

Returns an array of all the class methods that were defined in this class without the ones that were defined in it’s superclasses.

class FooBar
  def self.a_original_class_method
  end
end

class FooBarSubclass < FooBar
  def self.a_original_class_method_in_a_subclass
  end
end

FooBarSubclass.own_class_methods # => ['a_original_class_method_in_a_subclass']


38
39
40
# File 'lib/rucola/rucola_support/core_ext/ruby/object.rb', line 38

def self.own_class_methods
  metaclass.instance_methods - superclass.metaclass.instance_methods
end

Instance Method Details

#ivar(name) ⇒ Object

A mocha helper to get at an instance variable without having to use instance_variable_get.

obj.ivar(:some_ivar).expects(:foo)


7
8
9
# File 'lib/rucola/test_helper.rb', line 7

def ivar(name)
  instance_variable_get("@#{name}".to_sym)
end