Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby method tap

# before
def my_method
  o = User.new
  o.a = 1
  o.b = 2
  o.c = 3
  o
end

# after
def my_method
  User.new.tap do |o|
    o.a = 1
    o.b = 2
    o.c = 3
  end
end

# The tap method yields the calling object to the block and returns it.
 
PREVIOUS NEXT
Tagged: #ruby #method #tap
ADD COMMENT
Topic
Name
5+8 =