there is simple class,it can run,i have tested it
class Myfile
def self.openit(myfile)
file=open(myfile,‘r’)
while line=file.gets
puts line
end
file.close
end
end
Myfile.openit("/home/pt/code")
when i add it into gtk ,it can’t work.
here is my program:
require ‘gtk2’
button = Gtk::Button.new(“my ruby”)
button.signal_connect(“clicked”) {
Myfile.openit("/home/pt/code")
}
window = Gtk::Window.new
window.signal_connect(“delete_event”) {
puts “delete event occurred”
false
}
window.signal_connect(“destroy”) {
puts “destroy event occurred”
Gtk.main_quit
}
window.border_width = 10
window.add(button)
window.show_all
Gtk.main
class Myfile
def self.openit(myfile)
file=open(myfile,‘r’)
while line=file.gets
puts line
end
file.close
end
end
the outout is:
pt@pt-laptop:~$ ruby /home/pt/t10.rb
/home/pt/t10.rb:4: uninitialized constant Myfile
from /home/pt/t10.rb:27:in call' from /home/pt/t10.rb:27:in
main’
from /home/pt/t10.rb:27
how to revise it?