Dear all,
in Objective-C it is possible to split a method name into several
segments to be able to put a meaningful description before each
argument, like
(BOOL)containsPointX:(int)x Y:(int)y
At Thu, 8 May 2008 21:49:06 +0900,
Rick DeNatale wrote in [ruby-talk:301103]:
And in Ruby 1.9 you can also use the new hash literal syntax in the
call so it becomes:
contains_point x: value y: value
You forgot a comma between first value and y:.
However, the semantics of Ruby keyword/hash option parameters are
slightly different from the Smalltalk inspired Objective-C method
selectors. In Smalltalk/ObjectiveC x:y: is a different message and
will find a different method than y:x:, whereas Ruby keyword/hash
parameters are order independent and aren’t involved in resolving a
message to a method.
And the same selector can duplicate, x:x:x: is valid and
differs from x:, but it’s impossible with a hash.
And in Ruby 1.9 you can also use the new hash literal syntax in the
call so it becomes:
contains_point x: value y: value
Apple’s RubyCocoa, which is implementing Ruby on the Objective-C
runtime actually turns this into an objective-c call.
However, the semantics of Ruby keyword/hash option parameters are
slightly different from the Smalltalk inspired Objective-C method
selectors. In Smalltalk/ObjectiveC x:y: is a different message and
will find a different method than y:x:, whereas Ruby keyword/hash
parameters are order independent and aren’t involved in resolving a
message to a method.
On Thu, May 8, 2008 at 11:31 PM, Nobuyoshi N. [email protected]
wrote:
Hi,
At Thu, 8 May 2008 21:49:06 +0900,
Rick DeNatale wrote in [ruby-talk:301103]:
And in Ruby 1.9 you can also use the new hash literal syntax in the
call so it becomes:
contains_point x: value y: value
You forgot a comma between first value and y:.
You are correct of course, thanks.
However, the semantics of Ruby keyword/hash option parameters are
slightly different from the Smalltalk inspired Objective-C method
selectors. In Smalltalk/ObjectiveC x:y: is a different message and
will find a different method than y:x:, whereas Ruby keyword/hash
parameters are order independent and aren’t involved in resolving a
message to a method.
And the same selector can duplicate, x:x:x: is valid and
differs from x:, but it’s impossible with a hash.
thank you for all the suggestions. The Hash solution seem to be a
feasible workaround. I´ll try that. To bad there is no “real” way to
split the name in ruby…
Cheers,
– Jan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.