Class: Object
- Inherits:
- BasicObject
- Includes:
- InstanceExecHelper
- Defined in:
- lib/ruby/jruby_hack.rb,
lib/ruby/jruby_hack.rb,
lib/ruby/jruby_hack.rb,
lib/ruby/jruby_hack.rb
Overview
lib/ruby/try.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`.
-
#try(*args, &block) ⇒ Object
Sends the arguments to ‘self` or yields `self` (when `self` is non-`nil`).
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
406 407 408 |
# File 'lib/ruby/jruby_hack.rb', line 406 def bind yield self end |
#blank? ⇒ Boolean
Always ‘false`. Note that NilClass#blank? is overridden to return `true`
266 267 268 |
# File 'lib/ruby/jruby_hack.rb', line 266 def blank? false end |
#cons(array = []) ⇒ Array
Prepend the item to the front of a new list
381 382 383 |
# File 'lib/ruby/jruby_hack.rb', line 381 def cons(array = []) [self] + array end |
#eigenclass ⇒ Class
Return the “eigenclass” where singleton methods reside
427 428 429 |
# File 'lib/ruby/jruby_hack.rb', line 427 def eigenclass class << self; self; end end |
#instance_exec(*args, &block) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/ruby/jruby_hack.rb', line 293 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
270 271 272 |
# File 'lib/ruby/jruby_hack.rb', line 270 def present? true end |
#snoc(array = []) ⇒ Array
Append the item to rear of a new list
393 394 395 |
# File 'lib/ruby/jruby_hack.rb', line 393 def snoc(array = []) array + [self] end |
#tap {|_self| ... } ⇒ Object
Yields ‘self` to a side-effect block argument and return `self`
@example:
100.tap{|a| puts "debug: #{a}" } #=> 100
416 417 418 419 |
# File 'lib/ruby/jruby_hack.rb', line 416 def tap yield self self end |
#try(*args, &block) ⇒ Object
Sends the arguments to ‘self` or yields `self` (when `self` is non-`nil`). This is overridden by NilClass#try, which always returns `nil`.
657 658 659 660 661 662 663 |
# File 'lib/ruby/jruby_hack.rb', line 657 def try(*args, &block) if args.empty? yield self else __send__(*args, &block) end end |