Hi,
I’m a newbie in ruby.
I want to share some classes between different scripts.
Something like a small library.
How can I do this?
Thanks
Peter
Hi,
I’m a newbie in ruby.
I want to share some classes between different scripts.
Something like a small library.
How can I do this?
Thanks
Peter
Peter M. schrieb:
I want to share some classes between different scripts.
Something like a small library.How can I do this?
Put your code into modules and “require” them.
module Kewl #saved in kewl.rb
class Foo
def x
puts “hello”
end
end
end
And then use it:
require ‘kewl’
obj = Kewl::Foo.new
obj.x
Peter M. wrote:
Hi,
I’m a newbie in ruby.
I want to share some classes between different scripts.
Something like a small library.How can I do this?
Let’s say you have a bunch of Ruby source files, named “class(n).rb” in
the
current directory. Do this:
#!/usr/bin/ruby -w
require ‘class1.rb’
require ‘class2.rb’
require ‘class3.rb’
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs