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
Combinators (collapse)
-
- bind {|_self| ... }
Yields
selfto a block argument. -
- tap {|_self| ... }
Yields
selfto a side-effect block argument and returnself. -
- try(*args, &block)
Sends the arguments to
selfor yieldsself(whenselfis non-nil).
List Constructors (collapse)
-
- (Array) cons(array = [])
Prepend the item to the front of a new list.
-
- (Array) snoc(array = [])
Append the item to rear of a new list.
Instance Method Summary (collapse)
-
- (Boolean) blank?
Always
false. -
- (Class) eigenclass
Return the "eigenclass" where singleton methods reside.
- - instance_exec(*args, &block)
- - (Boolean) present?
Instance Method Details
- bind {|_self| ... }
Yields self to a block argument
39 40 41 |
# File 'lib/ruby/object.rb', line 39 def bind yield self end |
- (Boolean) blank?
Always false. Note that NilClass#blank? is overridden to return true
60 61 62 |
# File 'lib/ruby/blank.rb', line 60 def blank? false end |
- (Array) cons(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 |
- (Class) eigenclass
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)
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 |
- (Boolean) present?
64 65 66 |
# File 'lib/ruby/blank.rb', line 64 def present? true end |
- (Array) snoc(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| ... }
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 |
- try(*args, &block)
Sends the arguments to self or yields self (when self is non-nil).
This is overridden by NilClass#try, which always returns nil.
16 17 18 19 20 21 22 |
# File 'lib/ruby/try.rb', line 16 def try(*args, &block) if args.empty? yield self else __send__(*args, &block) end end |