[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01903] I'm stumped...!

From: "David Douthitt" <DDouthitt@...>
Date: 2000-03-16 17:09:24 UTC
List: ruby-talk #1903
Yes, I DO read the Ruby User Guide....

Yes, I DO read the Ruby Manual.....

But STILL I have many questions.............

What is happening in this code?  The code runs fine, but the commented out code generates the errors shown above each, and I don't know why.

#!/opt/ruby/bin/ruby

#---------------------------------
# Oracle Specific Functions
#---------------------------------

oratab = "/etc/oratab";

class ConfigFile < File
   def each_line
      super { |line|
         next if (line =~ /^(#|[ \t]*$)/);
         line.gsub!(/[ \t]+#.*$/, "");
         yield line;
         }
   end

   alias each each_line;
end

class Oratab < ConfigFile
   def open
      super(oratab)
   end

   def instances
      Oratab.open.each_line { |line|
         data = (line =~ /^([^:]+):/)
         yield data
         }
   end
end

class Instance
   def log (str, pri)
      `/bin/logger -t oracle -p #{pri} "#{str}"`
   end
end

#---------------------------------
# Program
#---------------------------------

ConfigFile.open(oratab).each_line { |line|
   line.chomp!;
   print line, "\n";
   }

#./ruby.functions:43:in `open': wrong # of arguments (0 for 1) (ArgumentError)
#       from ./ruby.functions:43
#Oratab.open.each_line { |line|
#   line.chomp!;
#   print line, "\n";
#   }

#./ruby.functions:57: undefined method `log' for Instance:Class (NameError)
#Instance.log("test", "info");

#./ruby.functions:51: undefined method `instances' for Oratab:Class (NameError)
#Oratab.instances { |inst|
#   print inst, " ";
#   }



In This Thread

Prev Next