Re: Execute block in context of yielding method's module
- From: Christian Leskowsky <christian.leskowsky@xxxxxxxxx>
- Date: Sun, 13 Nov 2005 12:28:04 +0900
Interesting... Thanks!
On 11/12/05, Ara.T.Howard <ara.t.howard@xxxxxxxx> wrote:
>
> On Sun, 13 Nov 2005, Christian Leskowsky wrote:
>
> > Hey guys,
> >
> > I'm very new to ruby.
> >
> > This is some freaky ***! Could somebody give me a use case as to when
> I'd
> > want to do something like this?
> >
> > Thanks!
>
>
> harp:~ > cat a.rb
> module Connection
> class << self
> def host arg = nil
> @host = arg if arg
> @host
> end
> def port arg = nil
> @port = arg if arg
> @port
> end
> def configure &block
> instance_eval &block
> end
> end
> end
>
> Connection::configure do
> host 'http://codeforpeople.com'
> port 80
> end
>
> p Connection::host
> p Connection::port
>
>
> harp:~ > ruby a.rb
> "http://codeforpeople.com"
> 80
>
>
> regards.
>
> -a
> --
>
> ===============================================================================
> | ara [dot] t [dot] howard [at] gmail [dot] com
> | all happiness comes from the desire for others to be happy. all misery
> | comes from the desire for oneself to be happy.
> | -- bodhicaryavatara
>
> ===============================================================================
>
>
>
--
-
'There was an owl lived in an oak.
The more he heard, the less he spoke.
The less he spoke, the more he heard.'
Christian Leskowsky
christian.leskowsky@xxxxxxxxx
- References:
- Execute block in context of yielding method's module
- From: Trans
- Re: Execute block in context of yielding method's module
- From: Sean O'Halpin
- Re: Execute block in context of yielding method's module
- From: Trans
- Re: Execute block in context of yielding method's module
- From: Christian Leskowsky
- Re: Execute block in context of yielding method's module
- From: Ara.T.Howard
- Execute block in context of yielding method's module
- Prev by Date: Re: Nested hash constructor confusion
- Next by Date: Re: Investigating Ruby - key limitations ?
- Previous by thread: Re: Execute block in context of yielding method's module
- Next by thread: Re: Execute block in context of yielding method's module
- Index(es):