Seeking advice on some method names

G

Glenn Parker

Gavin said:
I find #one quite uncompelling,
because it sounds like #any: it doesn't express its one_and_only_one
meaning.

Instead of "one", why not "lone", e.g. The Lone Ranger?
 
T

trans. (T. Onoma)

| > Gavin Sinclair wrote:
| >> I find #one quite uncompelling,
| >> because it sounds like #any: it doesn't express its one_and_only_one
| >> meaning.
| >
| > Instead of "one", why not "lone", e.g. The Lone Ranger?

Array#tonto

| Let's call it #singleton ;)

LOL :)
 
B

Brian Schröder

Instead of "one", why not "lone", e.g. The Lone Ranger?
Why not #scalar as it returns the scalar value of the array if the array is a 1-tuple.

Regards,

Brian
 
B

Brian Schröder

Why not #scalar as it returns the scalar value of the array if the array is a 1-tuple.

Sorry for the noise, I read the rejection further down only after sending this. (Though I still think #to_scalar more natural than #one, because #one does not convey a clear meaning to me)

e.g.

[].one => 1 (It returns one?)
[].one => true (It is only one array?)
[:a,:b,:c,:d].one => [1,1,1,1] (Fill with ones?)

Regards,

Brian
 
T

trans. (T. Onoma)

On Tuesday 30 November 2004 05:25 am, Brian Schröder wrote:
| Sorry for the noise, I read the rejection further down only after sending
| this. (Though I still think #to_scalar more natural than #one, because #one
| does not convey a clear meaning to me)
|
| e.g.
|
| [].one => 1 (It returns one?)
| [].one => true (It is only one array?)
| [:a,:b,:c,:d].one => [1,1,1,1] (Fill with ones?)

At first it occurred to me that this is nothing more than Array#first, except
that an error is desired if it isn't single. But this led me to another
oddity about #first, you can;t distinguish the results of these two forms:

[].first
[nil].first

To improve upon this leads me to three possibilities:

1) Live with it. It's manegable. :)

2) Introduce the concept of nack --which is an encapsulated
and diverted error. This has certain advantages, but
it is a "bigger" change.

[].first #=> nack
(f = [].first).nack_raise #=> (Exception)

where #nack_raise is defined in kernel to raise the nack if
it is one other wise return self.

3) Add a parameter to #first.

[].first:)empty) #=> (Exception)
[1].first:)empty) #=> 1
[1,2].first:)empty) #=> 1

[].first:)only) #=> (Exception)
[1].first:)only) #=> 1
[1,2].first:)only) #=> (Exception)

T.
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top