Class: Object

Inherits:
BasicObject
Defined in:
lib/shenanigans/object/it.rb,
lib/shenanigans/object/display.rb

Instance Method Summary collapse

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

#itObject

An identity method that provides access to an object’s self.

[1,2,3,4,5,1,2,2,3].group_by(&:it)
#=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}


6
7
8
# File 'lib/shenanigans/object/it.rb', line 6

def it
  self
end