Kenyans247 Forum

Welcome, Guest: Join Kenyans247 LOGIN!

Stats: 224 Members, 11,371 topics and 65 posts Date: Sunday 05 April 2020 at 04:30 PM
TrendingRecentNewestClassifiedDirectoryLivescoresLive Kenyan TVLive Kenyan Radio

Ruby Function (method) Syntax

Kenyans247 / Science/Technology / Programing / Ruby Function (method) Syntax (6 View's)

Ruby Function (method) Syntax Busy Nairobi Junction To Be Closed For 2 Months Ruby Function (method) Syntax How Well Does Your Leader Function In Times Of Crises And Darkest Of Hours?
(Go Down) (» Reply topic)
Ruby Function (method) Syntax by Kenyans247(m): Sun 22, March, 2020 08:23am
The Ruby language makes it easy to create functions.

Function Syntax

def functionname(variable)
return
end

Examples

Your function can compute values and store them in local variables that are specific to the function. Those values can then be returned with the return statement.

def say_hello(name)
var = “Hello, ” + name
return var
end

The return statement also can be shortened for very simple functions into a single line

def say_hello(name)
return “Hello, ” + name
end

You can simplify the function further. The last expression that is evaluated is automatically returned by the method. For example:

def say_hello(name)
“Hello, ” + name
end

This would return the same value as the prior functions.

To call a function

function param1, param2

or

function(param1,param2)

Example

puts say_hello(“Geek”)

https://www.howtogeek.com/howto/programming/ruby/ruby-function-method-syntax/

(» Reply topic) (» Go Up)

Recommended for you

» Ruby Function (method) Syntax » Busy Nairobi Junction To Be Closed For 2 Months » Ruby Function (method) Syntax » How Well Does Your Leader Function In Times Of Crises And Darkest Of Hours?
Viewing this topic:
1 guest(s) viewing this topic

Sections: Investment, Naija Forums, Environment, Kenyans247 ads, Career, Innovation, Phones, Building/Architecture, Programing, Art, Graphics & Video, TV/Movies, Fashion, Lifestyle, Photography, Forum Games, South Sudan Forum, Ugandan Forum, Burundi Forum, Rwanda Forum, Somalia Forum,

Kenyans247 - Copyright © 2019 - 2020 Sande Kennedy. All rights reserved. See How To Advertise.
Disclaimer: Every Kenyans247 member is solely responsible for anything that he/she posts or uploads on Kenyans247.