Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/shenanigans/object/display.rb,
lib/shenanigans/object/identity.rb
Instance Method Summary collapse
-
#display(new_line = true) ⇒ Object
(also: #d)
Outputs the object and also returns it.
-
#identity ⇒ Object
An identity method that provides access to an object’s
self
.
Instance Method Details
#display(new_line = true) ⇒ Object Also known as: d
Outputs the object and also returns it. Will use puts
if new_line
is true
and print
otherwise.
"foo".display
foo
#=> "foo"
"foo".display(false)
foo#=> "foo"
11 12 13 14 |
# File 'lib/shenanigans/object/display.rb', line 11 def display(new_line = true) m = new_line ? :puts : :print self.tap { |o| send(m, o) } end |
#identity ⇒ Object
An identity method that provides access to an object’s self
.
[1,2,3,4,5,1,2,2,3].group_by(&:identity)
#=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
6 7 8 |
# File 'lib/shenanigans/object/identity.rb', line 6 def identity self end |