[#4567] Re: What's the biggest Ruby development? — Aleksi Niemel<aleksi.niemela@...>

Dave said:

18 messages 2000/08/23
[#4568] Q's on Marshal — Robert Feldt <feldt@...> 2000/08/23

[#4580] RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/25

[#4584] Re: RubyUnit testcase run for different init params? — Dave Thomas <Dave@...> 2000/08/25

Robert Feldt <feldt@ce.chalmers.se> writes:

[#4623] Re: RubyUnit testcase run for different init params? — Robert Feldt <feldt@...> 2000/08/28

On Sat, 26 Aug 2000, Dave Thomas wrote:

[#4652] Andy and Dave's European Tour 2000 — Dave Thomas <Dave@...>

24 messages 2000/08/30
[#4653] Re: Andy and Dave's European Tour 2000 — matz@... (Yukihiro Matsumoto) 2000/08/30

Hi,

[#4657] Ruby tutorials for newbie — Kevin Liang <kevin@...> 2000/08/30

Hi,

[ruby-talk:4636] Re: Class methods

From: Mark Slagell <ms@...>
Date: 2000-08-29 14:03:35 UTC
List: ruby-talk #4636
Lovely stuff!  Thanks.  The block_given? line gives me a "stack level too deep"
error (wassat mean?) but the rest fits the bill nicely.

Is there anyplace where things like method_missing are documented?

  Mark


Dave Thomas wrote:

> How about this solution, written in Ruby, that seems to do what you
> want?
>
>      class Class
>        def method_missing(meth, *params)
>          if block_given?
>            self.new(*params).send(meth) { |*p| yield *p }
>          else
>            self.new(*params).send(meth)
>          end
>        end
>      end
>
> This is called using things like:
>
>      File.each("t.rb") { |line| puts line }
>
> By putting the handler in class Class, the technique automatically
> applies to every class in the system. And, by writing it in Ruby, you
> can make it a module that you require into your code as you
> need. Finally, it doesn't add any additional methods to the core.
>
> The downside is that you'll get weird errors if you call a real
> unknown method, so we should probably put some better error handling
> in here. That's left as an exercise...
>
> Regards
>
> Dave


In This Thread