On Mon, Aug 27, 2012 at 4:12 PM, Dipesh Gtm <[email protected]> wrote:
> Sorry, I should have posted more code. The code below does not work but
> I
> think you will get the idea.
>
> class Food
>  def plate(&block)
>   extend Operators
>   include Operations

That line above does not make sense since you can only include a
module in a class or module.  Also, it's a questionable habit to
extend multiple times with the same module.  That is inefficient.

>   instance_eval(&block)
>  end
>
>
>  plate do
>   eat do |d|
>    d.pepsi, 20
>    d.coke, 10
>   end
>  end

Method plate is not defined for the class.  Also it's a bad idea to
have similarly named methods for class and instance.

> end
>
> module Operations
>  attr_accessor :bloc
>  def serve(&block)
>   @bloc[:serve] = block
>  end
>  def eat(&block)
>   @bloc[:eat] = block
>  end
> end
>
> module Operators
>  def serve!
>   @bloc[:serve].call(self)
>  end
> end
>
> Then, when I do
>  Food.new.serve!
>
> I wanted it to trigger the pepsi and coke methods on instance level with
> corresponding
> arguments. I have not included those methods here though.

Why?  How are we supposed to understand your use case?

> I wanted to define my methods inside the Operations module via method
> missing. But since it was extended, I was looking for a scope to tie up
> to.

> Hope that made sense.

Frankly, no - at least not to me.

> And Thanks. If you guys say there's a better way
> available, I would be happy to post the working code.

I would need to understand what your goal is.  It's not clear to me
yet.  Can you describe your use case more abstractly than with a
solution in mind?  What are your requirements and goals?

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to