Ask a Question related to Ruby, Design and Development.
-
Rasputin #1
Kernel.const_get and gets
Well, rubberducking has finally failed me.
Using Kernel.const_get() to dynamically create instances seems
to screw up their idea of STDIN. I'm probably missing something
obvious, please can someone enlighten me?
-Program:-----------------------------
1rasputin@lb:roxo$ cat confused.rb
#! /usr/pkg/bin/ruby -w
class Echo
def echo
puts "#{self.class} would like a string:"
puts gets
end
end
class Rev
def echo
puts "#{self.class} would like a string:"
puts gets.reverse
end
end
oldschool = [ Rev.new, Echo.new ]
dynamic = []
ARGV.each { |c| dynamic << Kernel.const_get(c).new }
oldschool.each { |i| i.echo }
dynamic.each { |i| i.echo }
1rasputin@lb:roxo$
--------------------------------------
-Sample output:-----------------------
0rasputin@lb:roxo$ ./confused.rb
Rev would like a string:
teststr
rtstset
Echo would like a string:
wibble
wibble
0rasputin@lb:roxo$ ./confused.rb Rev Echo
Rev would like a string:
./confused.rb:13:in `gets': No such file or directory - "Rev" (Errno::ENOENT)
from ./confused.rb:13:in `echo'
from ./confused.rb:22
from ./confused.rb:22:in `each'
from ./confused.rb:22
--------------------------------------
1rasputin@lb:roxo$ ruby -v
ruby 1.6.8 (2002-12-24) [i386-netbsdelf]
Todays CVS gives the same error.
Baffled is an understatement. This is part of a much larger program,
so it's taken me a little while to narrow it down.
--
Gee, Toto, I don't think we are in Kansas anymore.
Rasputin :: Jack of All Trades - Master of Nuns
Rasputin Guest
-
Kernel
Just wondering, what changes, if any have been made to the OS kernel? Is it still explorer.exe? Is the browser still highly integrated? Has it... -
kernel-source versus kernel-patch
Hi, The description of the kernel-source-2.4.21 package says "Linux kernel source for version 2.4.21 with Debian patches". But, there is another... -
kernel 2.2.x or 2.4.x ?
On Sunday 06 July 2003 22:12, Shango Oluwa wrote: Mostly because the 2.4 series had some serious (as in "don't use for production machines")... -
How to apply no-debianized kernel patch to debianized kernel-source?
Hello everybody I (like many others in the last few days) have a problem with kernel 2.4.21. I have downloaded the kernel-source-2.4.21 deb, and... -
Kernel 2.4.20
Hi all. I downloaded the file: kernel-source-2.4.20_2.4.20-8_all.deb then ran dpkg -i kernel-source-2.4.20_2.4.20-8_all.deb Ran dselect, and... -
Jay Adkisson #2
Re: Kernel.const_get and gets
Odd. A workaround is to explicitly name the receiver of `gets`:
class Rev
def echo
puts "#{self.class} would like a string:"
puts $stdin.gets.reverse
end
end
Junior Member
- Join Date
- Dec 2010
- Posts
- 1



Reply With Quote

