Personal methods on Ruby | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Personal methods on Ruby

Hi everyone, i was wondering if there is a way to implement our methods in ruby. For example, i defined a method that return as many empty lines as we want, and i'm using this in every script. The question is, can i use my method without defining it on every script? Thanks for your reply

11th Mar 2017, 3:31 PM
Luca Ortis
Luca Ortis - avatar
7 Answers
+ 8
Also by the way you can do alot of awesome and creative codes using require, happy coding! :D
17th Mar 2017, 11:06 PM
MrCoder
MrCoder - avatar
+ 7
First simply make a code where your own method is written in and in the other code at the first line (If possible) write this: x is the name of the code whete your own method is. require 'x.rb' for example: class LucaOrtisIsAwesome def awe puts "Why am I here?" end end (Code saved as: awesome) (Open Another Code Tab) require 'awesome.rb' c = LucaOrtisIsAwesome.new c.awe Outputs: "Why am I here?" Hope this helps
17th Mar 2017, 1:39 AM
MrCoder
MrCoder - avatar
+ 6
Definitely fun! We can code together man! :)
19th Mar 2017, 1:02 AM
MrCoder
MrCoder - avatar
+ 6
Yeah it would be! :D
19th Mar 2017, 3:03 AM
MrCoder
MrCoder - avatar
+ 3
yes this helps, thanks!! I didn't thought about require..
17th Mar 2017, 2:24 PM
Luca Ortis
Luca Ortis - avatar
+ 1
yeah you can say that! i posted a new code that requires multiple file to work properly.. Ruby it's really awesome
18th Mar 2017, 4:03 PM
Luca Ortis
Luca Ortis - avatar
+ 1
that would be great!!
19th Mar 2017, 1:36 AM
Luca Ortis
Luca Ortis - avatar