Class: Object
- Inherits:
- BasicObject
- Includes:
- InstanceExecHelper
- Defined in:
- lib/ruby/try.rb,
lib/ruby/blank.rb,
lib/ruby/object.rb,
lib/ruby/instance_exec.rb
Defined Under Namespace
Modules: InstanceExecHelper
List Constructors collapse
-
#cons(array = []) ⇒ Array
Prepend the item to the front of a new list.
-
#snoc(array = []) ⇒ Array
Append the item to rear of a new list.
Combinators collapse
-
#bind {|_self| ... } ⇒ Object
Yields ‘self` to a block argument.
-
#tap {|_self| ... } ⇒ Object
Yields ‘self` to a side-effect block argument and return `self`.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Always ‘false`.
-
#eigenclass ⇒ Class
Return the “eigenclass” where singleton methods reside.
- #instance_exec(*args, &block) ⇒ Object
- #present? ⇒ Boolean
Instance Method Details
#bind {|_self| ... } ⇒ Object
Yields ‘self` to a block argument
39 40 41 |
# File 'lib/ruby/object.rb', line 39 def bind yield self end |
#blank? ⇒ Boolean
Always ‘false`. Note that NilClass#blank? is overridden to return `true`
62 63 64 |
# File 'lib/ruby/blank.rb', line 62 def blank? false end |
#cons(array = []) ⇒ Array
Prepend the item to the front of a new list
14 15 16 |
# File 'lib/ruby/object.rb', line 14 def cons(array = []) [self] + array end |
#eigenclass ⇒ Class
Return the “eigenclass” where singleton methods reside
60 61 62 |
# File 'lib/ruby/object.rb', line 60 def eigenclass class << self; self; end end |
#instance_exec(*args, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby/instance_exec.rb', line 8 def instance_exec(*args, &block) thread = Thread.current.object_id.abs object = object_id.abs mname = "__instance_exec_#{thread}_#{object}" InstanceExecHelper.module_eval { define_method(mname, &block) } begin __send__(mname, *args) ensure begin InstanceExecHelper.module_eval { remove_method(mname) } rescue end end end |
#present? ⇒ Boolean
66 67 68 |
# File 'lib/ruby/blank.rb', line 66 def present? true end |
#snoc(array = []) ⇒ Array
Append the item to rear of a new list
26 27 28 |
# File 'lib/ruby/object.rb', line 26 def snoc(array = []) array + [self] end |
#tap {|_self| ... } ⇒ Object
Yields ‘self` to a side-effect block argument and return `self`
@example:
100.bind{|a| puts "debug: #{a}" } #=> 100
49 50 51 52 |
# File 'lib/ruby/object.rb', line 49 def tap yield self self end |