Refinements

I

Intransition

<a href="http://timeless.judofyr.net/refinements-in-ruby">Refinements</
a> are similar to the namespace approach proposed long ago. The key
difference being #using to active the patches. Based on the older
idea, I wonder if the #refine method is actually necessary. Would this
not do as well?

module TimeExtensions
class Fixnum
def minutes; self * 60; end
end
end

class MyApp
using TimeExtensions

def initialize
p 2.minutes
end
end
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

I'm not really sure I see a useful distinction from DelegateClass. How is:

module Foo
refine Bar do
def baz; ...; end
end
end

really that different from:

module Foo
class Bar < DelegateClass:):Bar)
def baz; ...; end
end
end

except for a slightly more terse syntax?
 
I

Intransition

I'm not really sure I see a useful distinction from DelegateClass. How is= :

=A0 =A0 module Foo
=A0 =A0 =A0 refine Bar do
=A0 =A0 =A0 =A0 def baz; ...; end
=A0 =A0 =A0 end
=A0 =A0 end

really that different from:

=A0 =A0 module Foo
=A0 =A0 =A0 class Bar < DelegateClass:):Bar)
=A0 =A0 =A0 =A0 def baz; ...; end
=A0 =A0 =A0 end
=A0 =A0 end

except for a slightly more terse syntax?

Why even use DelegateClass ?

module Foo
class Bar < ::Bar
def baz; ...; end
end
end

And it's a good question (this is exactly the namespace idea that was
proposed long ago, btw). The only thing in the way of doing this is
Ruby's lack of support for literals. That is to say, if I created an
extended String, Foo::String, then literal string notation within the
scope of Foo should use that. But I am guessing their are possible
subtitles I am missing. Can any one fill us in?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top