Feature #5899

chaining comparsions.

Added by neleai (Ondrej Bilka) 4 months ago. Updated about 1 month ago.

[ruby-core:42149]
Status:Feedback Start date:01/16/2012
Priority:Normal Due date:
Assignee:matz (Yukihiro Matsumoto) % Done:

0%

Category:Joke
Target version:-

Description

Migration from python to ruby is problematic because ruby lacks certain features. Most important python advantage is chained comparison We must wrap every comparison like described below. puts "yes" if 1<2<3<4 class Fixnum def <(a) ((self<=>a)==-1)&&a end end class FalseClass def <(a) false end end

History

Updated by Anonymous 4 months ago

Ondrej Bilka wrote in post #1041080: > Issue #5899 has been reported by Ondrej Bilka. > > ---------------------------------------- > Feature #5899: chaining comparsions. > https://bugs.ruby-lang.org/issues/5899 > > puts "yes" if 1<2<3<4 > +1 -- Posted via http://www.ruby-forum.com/.

Updated by kernigh (George Koehler) 4 months ago

What is a good way to do chained comparison in Ruby?

My best attempt, so far, is

[1, 2, 3, 4].each_cons(2).all? {|a, b| a < b}

Updated by naruse (Yui NARUSE) 4 months ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

Updated by matz (Yukihiro Matsumoto) about 1 month ago

  • Status changed from Assigned to Feedback
I don't think changing "1 < b < 4" to "1 < b && b < 4" is that hard task. I am not sure it's worth allowing confusing "false < 4". Matz.

Updated by neleai (Ondrej Bilka) about 1 month ago

On Sun, Apr 01, 2012 at 02:30:31AM +0900, matz (Yukihiro Matsumoto) wrote: > > Issue #5899 has been updated by matz (Yukihiro Matsumoto). > > Status changed from Assigned to Feedback > > I don't think changing "1 < b < 4" to "1 < b && b < 4" is that hard task. > I am not sure it's worth allowing confusing "false < 4". As false goes I would like to define sentinels by inheriting from FalseClass which is separate feature. > > Matz. > > ---------------------------------------- > Feature #5899: chaining comparsions. > https://bugs.ruby-lang.org/issues/5899#change-25543 > > Author: neleai (Ondrej Bilka) > Status: Feedback > Priority: Normal > Assignee: matz (Yukihiro Matsumoto) > Category: Joke > Target version: > > > Migration from python to ruby is problematic because ruby lacks certain features. > Most important python advantage is chained comparison > We must wrap every comparison like described below. > > puts "yes" if 1<2<3<4 > > class Fixnum > def <(a) > ((self<=>a)==-1)&&a > end > end > class FalseClass > def <(a) > false > end > end > > > > > -- > http://bugs.ruby-lang.org/ -- Sysadmins busy fighting SPAM.

Also available in: Atom PDF