+ 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
7 Respostas
+ 8
Also by the way you can do alot of awesome and creative codes using require, happy coding! :D
+ 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
+ 6
Definitely fun! We can code together man! :)
+ 6
Yeah it would be! :D
+ 3
yes this helps, thanks!! I didn't thought about require..
+ 1
yeah you can say that! i posted a new code that requires multiple file to work properly.. Ruby it's really awesome
+ 1
that would be great!!