DEV Community

es404020
es404020

Posted on

2 2

Methods in Ruby

Methods or Function in ruby allows us to put our code in a container and call it when necessary. This allows reusability and prevent duplication ,take for instance we want multiply 3 different pairs of number 9 time we would do this

puts "#{3 * 4}"
puts "#{1 * 0}"
puts "#{8 * 2}"
puts "#{7 * 6}"
.....

Enter fullscreen mode Exit fullscreen mode

This would be a very long and repetitive process but with methods we can do this.

def multiply(a,b)
    a*b
end
multiply(3,4)
multiply(1,0)


Enter fullscreen mode Exit fullscreen mode

This is easier to maintain and be used by anyone

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay