{"id":9740,"date":"2024-03-05T05:42:35","date_gmt":"2024-03-05T05:42:35","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=9740"},"modified":"2024-03-05T05:42:35","modified_gmt":"2024-03-05T05:42:35","slug":"ruby-methods-returning-results-in-replit","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/ruby-on-rails\/ruby-methods-returning-results-in-replit","title":{"rendered":"Ruby Methods Returning Results in repl.it But Not When Run the Program"},"content":{"rendered":"<p>The last expression evaluated in a method is implicitly returned. In this rev method, the last line is c.join(&#8216; &#8216;), which is the expression whose value you want to return. However, in this example, you&#8217;re not seeing the returned value because you&#8217;re only invoking the method rev(&#8216;hello&#8217;), but you&#8217;re not doing anything with the returned value.<\/p>\n<p>To capture the returned value and use it, you need to assign it to a variable or use it directly. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">result = rev('hello')\r\nputs result\r\n<\/pre>\n<p>This will capture the returned value of rev(&#8216;hello&#8217;) in the variable result, and then print it using puts.<\/p>\n<p>Alternatively, you can directly use the returned value:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">\r\nputs rev('hello')\r\n<\/pre>\n<p>Both of these approaches will print the reversed string &#8220;olleh&#8221;, which is the returned value of your rev method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The last expression evaluated in a method is implicitly returned. In this rev method, the last line is c.join(&#8216; &#8216;), which is the expression whose value you want to return. However, in this example, you&#8217;re not seeing the returned value because you&#8217;re only invoking the method rev(&#8216;hello&#8217;), but you&#8217;re not doing anything with the returned [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9742,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-9740","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9740"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=9740"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9740\/revisions"}],"predecessor-version":[{"id":9744,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9740\/revisions\/9744"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/9742"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=9740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=9740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=9740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}