Class: Object

Inherits:
BasicObject
Includes:
InstanceExecMethods
Defined in:
lib/support/active_support_lite/misc.rb,
lib/support/core_ext.rb,
lib/support/active_support_lite/blank.rb,
lib/support/active_support_lite/object.rb

Overview

:nodoc:all

Defined Under Namespace

Modules: InstanceExecMethods

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

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

This simplifies

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

to

if !address.blank?

:nodoc

Returns:

  • (Boolean)


13
14
15
# File 'lib/support/active_support_lite/blank.rb', line 13

def blank?
  respond_to?(:empty?) ? empty? : !self
end

#extended_byObject

:nodoc



4
5
6
7
# File 'lib/support/active_support_lite/object.rb', line 4

def extended_by #:nodoc
  ancestors = class << self; ancestors end
  ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ]
end

#instance_exec(*args, &block) ⇒ Object

Evaluate the block with the given arguments within the context of this object, so self is set to the method receiver.

From Mauricio’s eigenclass.org/hiki/bounded+space+instance_exec



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/support/core_ext.rb', line 50

def instance_exec(*args, &block)
  begin
    old_critical, Thread.critical = Thread.critical, true
    n = 0
    n += 1 while respond_to?(method_name = "__instance_exec#{n}")
    InstanceExecMethods.module_eval { define_method(method_name, &block) }
  ensure
    Thread.critical = old_critical
  end

  begin
    send(method_name, *args)
  ensure
    InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
  end
end

#present?Boolean

:nodoc

Returns:

  • (Boolean)


19
20
21
# File 'lib/support/active_support_lite/blank.rb', line 19

def present?
  !blank?
end

#returning(value) {|value| ... } ⇒ Object

:nodoc

Yields:

  • (value)


39
40
41
42
# File 'lib/support/active_support_lite/misc.rb', line 39

def returning(value)
  yield(value)
  value
end