I would expect that method calls and proc calls do not differ in such a
way.
Is this a bug or a feature?
I think it’s rather a feature although I can understand your surprise.
IIRC block (and thus proc) parameters behave more similar to
assignments:
def t
yield 1
yield [2]
yield [3,4]
end
=> nil
t {|a| p a}
1
[2]
[3, 4]
=> nil
t {|a,*b| p a}
1
2
3
=> nil
t {|a,| p a}
1
2
3
=> nil
15:04:11 [~]: ruby -e ‘a=1; p a; a=[2,3]; p a’
1
[2, 3]
15:04:45 [~]: ruby -e ‘a=1; p a; a=[2]; p a; a=[3,4]; p a’
1
[2]
[3, 4]
15:05:08 [~]: ruby -e ‘a,*b=1; p a; a,*b=[2]; p a; a,*b=[3,4]; p a’
1
2
3
15:05:25 [~]: ruby -e ‘a,=1; p a; a,=[2]; p a; a,=[3,4]; p a’
1
2
3
15:05:34 [~]:
In message “Re: Next Major Version (was Re: Different semantics of Proc
and method call – bug or feature?)”
on Wed, 2 Aug 2006 23:14:32 +0900, James Edward G. II [email protected] writes:
|On Aug 2, 2006, at 9:05 AM, Yukihiro M. wrote:
|
|> It’s a feature, but we are trying to fix it in the next major release
|> (1.9 or 2.0).
|
|Matz, could you tell us why you are considering releasing the next
|major version as 1.9 instead of 2.0?
In the current pace, it would take years to release 2.0, but some
requested features we already made in 1.9 branch. We felt the request
is reasonable.
In message “Re: Next Major Version (was Re: Different semantics of Proc
and method call – bug or feature?)”
on Thu, 3 Aug 2006 00:38:41 +0900, “N Okia” [email protected]
writes:
|In keeping with your current numbering scheme, does this mean there
|will be a ruby 1.10 release?
The version letters will be stay in one letter each, so that 1.a will
be more likely than 1.10.
I hesitate to ask YOU this, but are you really sure you want to go that
way.
Almost every software package I’ve run across keeps each level of the
version “number” as a number, so 1.10 would be much more in line with
standard practice than 1.a
Almost every software package I’ve run across keeps each level of the
version “number” as a number, so 1.10 would be much more in line with
standard practice than 1.a
But it can’t be compared properly using Ruby operators:
The version letters will be stay in one letter each, so that 1.a will
be more likely than 1.10.
=> false
Ah, but doing the comparison correctly in Ruby isn’t that hard, in a
few minutes I came up with:
irb(main):023:0> class Version
irb(main):024:1> include Comparable
irb(main):025:1>
irb(main):026:1* def initialize(string)
irb(main):027:2> @value = string.split(’.’).collect { | i |
i.to_i }
irb(main):028:2> end
irb(main):029:1>
irb(main):030:1* def <=>(another)
irb(main):031:2> @value <=> another.to_ary
irb(main):032:2> end
irb(main):033:1>
irb(main):034:1* def to_ary
irb(main):035:2> @value
irb(main):036:2> end
irb(main):037:1> end
=> nil
irb(main):038:0> Version.new(“1.8.5”)
=> #<Version:0xb7d728e8 @value=[1, 8, 5]>
irb(main):039:0> Version.new(“1.8.5”) < Version.new(“1.10.0”)
=> true
I’d strongly suggest, that it’s much better for Ruby if it tries to
stay in line as much as possible with how things are done in the open
source community.
There’s a lot of software outside of Ruby which depends on having
versions being a tuple of numbers. Since Ruby makes it easy to meet
things like that more than halfway, I think that it’s better to do so.
irb(main):027:2> @value = string.split(’.’).collect { | i | i.to_i }
=> nil
versions being a tuple of numbers. Since Ruby makes it easy to meet
things like that more than halfway, I think that it’s better to do so.
|In keeping with your current numbering scheme, does this mean there
that way.
Almost every software package I’ve run across keeps each level of the
version “number” as a number, so 1.10 would be much more in line with
standard practice than 1.a
But it can’t be compared properly using Ruby operators:
“1.8.5” < “1.10.0”
=> false
Which is another good reason for Ruby to have an actual Tuple class.
number
I’m not sure I see the point. Each level has less signficance than
the one before. I’m pretty sure that’s how the code I posted orders
versions.
In message “Re: Next Major Version (was Re: Different semantics of Proc
and method call – bug or feature?)”
on Fri, 4 Aug 2006 00:26:39 +0900, “Rick DeNatale” [email protected] writes:
|> The version letters will be stay in one letter each, so that 1.a will
|> be more likely than 1.10.
|Matz,
|
|I hesitate to ask YOU this, but are you really sure you want to go that way.
|
|Almost every software package I’ve run across keeps each level of the
|version “number” as a number, so 1.10 would be much more in line with
|standard practice than 1.a
Ah, well, I forgot to put smiley after the sentence. No, we are not
going to name it neither “1.a” nor “1.10”. 1.8.9 will be the last
release of the current stable series. And 1.9 will be the last of the
1.x.
versions.
you are right about that - i gues i was simply pointing out that, in
order to
be correct with present open source standards one needs something that
works
like
version(‘1.2.1’) =~ version(‘1.1.0’) #=> true
in otherwords, you need compaisson which implies compatibility, not just
gt
and lt.
regards.
-a
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.