E
Eric Mahurin
I'm thinking of yet another RCR and would like to see if
anybody likes it. I think this would be a sweet feature. Here
are the basic components:
1. Allow a null/default method to be defined in a class so that
the syntax "obj(*args,&block)" could be used. obj could be any
expression yielding a object. When you try to treat that
object as a method passing arguments and/or attaching a code
block to it, the null/default method would be called. I was
thinking "@" would be a good name for this method - like "+@"
and "-@". Here are a few example uses:
* klass(*args) : you alias the null method to "new" so that
this would be equivalent ot klass.new(*args). I tend to forget
the ".new" more often than I'd like to admit.
* obj() : this could be aliased to clone in Object so that
default would be to just obj.clone
* enum {...} : you could alias the null method to "each" so
that this would be equivalent to enum.each {...}
2. Allow an assignment method to be defined for an object ('='
is probably best). This would be called when you find an
object expression on the LHS whereas #1 is the equivalent for
the RHS. The ugly thing about this is that you have to make
sure that the object being assigned looks like an expression as
opposed to a variable or attribute assignment - surrounding is
parentheses makes it an expression that is normally illegal to
assign to. Along with '=', '+=', '-=', etc. becomes meaningful
in this context. You could also incorporate RCR 157/307 in
there allowing arguments. Here are a few example uses for
this:
* (str) = value : this could default to "replace" for any
objects that respond to it (or if you use evil.rb - "become")
* (mutable) += value : now the real += can be implemented for
this since you are accessing the object rather than assigning
the variable. Of course Fixnum is immutable, so it doesn't do
you any good there. Other mutable classes (or ones that could
be made mutable - Float) could take advantage of this (for
example Array).
I was mainly wanting #1, the complementary #2 looks pretty
useful too.
__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail
anybody likes it. I think this would be a sweet feature. Here
are the basic components:
1. Allow a null/default method to be defined in a class so that
the syntax "obj(*args,&block)" could be used. obj could be any
expression yielding a object. When you try to treat that
object as a method passing arguments and/or attaching a code
block to it, the null/default method would be called. I was
thinking "@" would be a good name for this method - like "+@"
and "-@". Here are a few example uses:
* klass(*args) : you alias the null method to "new" so that
this would be equivalent ot klass.new(*args). I tend to forget
the ".new" more often than I'd like to admit.
* obj() : this could be aliased to clone in Object so that
default would be to just obj.clone
* enum {...} : you could alias the null method to "each" so
that this would be equivalent to enum.each {...}
2. Allow an assignment method to be defined for an object ('='
is probably best). This would be called when you find an
object expression on the LHS whereas #1 is the equivalent for
the RHS. The ugly thing about this is that you have to make
sure that the object being assigned looks like an expression as
opposed to a variable or attribute assignment - surrounding is
parentheses makes it an expression that is normally illegal to
assign to. Along with '=', '+=', '-=', etc. becomes meaningful
in this context. You could also incorporate RCR 157/307 in
there allowing arguments. Here are a few example uses for
this:
* (str) = value : this could default to "replace" for any
objects that respond to it (or if you use evil.rb - "become")
* (mutable) += value : now the real += can be implemented for
this since you are accessing the object rather than assigning
the variable. Of course Fixnum is immutable, so it doesn't do
you any good there. Other mutable classes (or ones that could
be made mutable - Float) could take advantage of this (for
example Array).
I was mainly wanting #1, the complementary #2 looks pretty
useful too.
__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail