class Object

whytheluckystiff.net/articles/seeingMetaclassesClearly.html

Public Class Methods

unique_methods() click to toggle source

Lists methods unique to a class.

# File lib/ext/object.rb, line 8
def self.unique_methods
  (public_methods - Object.methods).sort.map(&:to_sym)
end

Public Instance Methods

args_and_opts(*args) click to toggle source

Returns a list of arguments and an options hash. Source taken from RSpec.

# File lib/ext/object.rb, line 13
def args_and_opts(*args)
  options = Hash === args.last ? args.pop : {}
  return args, options
end
blank?() click to toggle source

An object is blank if it’s nil, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are blank.

This simplifies

if !address.nil? && !address.empty?

to

if !address.blank?
# File lib/inactive_support/core_ext/blank.rb, line 9
def blank?
  respond_to?(:empty?) ? empty? : !self
end
class_def(name, &blk) click to toggle source

Defines an instance method within a class

# File lib/ext/metaclass.rb, line 14
def class_def name, &blk
  class_eval { define_method name, &blk }
end
meta_def(name, &blk) click to toggle source

Adds methods to a metaclass

# File lib/ext/metaclass.rb, line 9
def meta_def name, &blk
  meta_eval { define_method name, &blk }
end
meta_eval(&blk) click to toggle source
# File lib/ext/metaclass.rb, line 6
def meta_eval(&blk); metaclass.instance_eval(&blk); end
metaclass() click to toggle source

The hidden singleton lurks behind everyone

# File lib/ext/metaclass.rb, line 5
def metaclass; class << self; self; end; end
unique_methods() click to toggle source

Lists methods unique to an instance.

# File lib/ext/object.rb, line 3
def unique_methods
  (public_methods - Object.methods).sort.map(&:to_sym)
end