Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
March 5, 2024
The last expression evaluated in a method is implicitly returned. In this rev method, the last line is c.join(‘ ‘), which is the expression whose value you want to return. However, in this example, you’re not seeing the returned value because you’re only invoking the method rev(‘hello’), but you’re not doing anything with the returned value.
To capture the returned value and use it, you need to assign it to a variable or use it directly. For example:
result = rev('hello') puts result
This will capture the returned value of rev(‘hello’) in the variable result, and then print it using puts.
Alternatively, you can directly use the returned value:
puts rev('hello')
Both of these approaches will print the reversed string “olleh”, which is the returned value of your rev method.