# Segmented method names

**URL:** <https://www.ruby-forum.com/t/segmented-method-names/137033>\
**Category:** Ruby\
**Created:** [May 8, 2008, 1:56pm UTC](https://www.ruby-forum.com/t/segmented-method-names/137033 "2008-05-08T13:56:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jahu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jahu](https://www.ruby-forum.com/u/jahu)\
**Post date:** [May 8, 2008, 1:56pm UTC](https://www.ruby-forum.com/t/segmented-method-names/137033/1 "2008-05-08T13:56:47Z")

</div>

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

is there a ruby way to achieve something similar?

Many TIA,  
– Jan

---

<div class="post-metadata">

**Author:** ![jahu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jahu](https://www.ruby-forum.com/u/jahu)\
**Post date:** [May 8, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/segmented-method-names/137033/2 "2008-05-08T14:33:29Z")

</div>

A solution can be:

#function  
def contains\_point(opts = { :x=\>nil, :y=\>nil })

end

# call

contains\_point :x=\>value, :y=\>value

---

<div class="post-metadata">

**Author:** ![jahu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jahu](https://www.ruby-forum.com/u/jahu)\
**Post date:** [May 9, 2008, 5:32am UTC](https://www.ruby-forum.com/t/segmented-method-names/137033/3 "2008-05-09T05:32:03Z")

</div>

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:.

> 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.

---

<div class="post-metadata">

**Author:** ![jahu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jahu](https://www.ruby-forum.com/u/jahu)\
**Post date:** [May 8, 2008, 2:50pm UTC](https://www.ruby-forum.com/t/segmented-method-names/137033/4 "2008-05-08T14:50:04Z")

</div>

On Thu, May 8, 2008 at 8:32 AM, Sandro P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> # call
> 
> contains\_point :x=\>value, :y=\>value

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.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![jahu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jahu](https://www.ruby-forum.com/u/jahu)\
**Post date:** [May 9, 2008, 2:56pm UTC](https://www.ruby-forum.com/t/segmented-method-names/137033/5 "2008-05-09T14:56:26Z")

</div>

On Thu, May 8, 2008 at 11:31 PM, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

Good point.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![jahu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@jahu](https://www.ruby-forum.com/u/jahu)\
**Post date:** [May 9, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/segmented-method-names/137033/6 "2008-05-09T14:13:36Z")

</div>

Hi,

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
