Page 3 of 760 results found for <=> ruby
read_unordered_set(:user1, :user2) #=> 2 read_unordered_set(:user2, :user1) #=> 2 How can I get a similar behaviour in Ruby? Tags: ruby The missing part here is a <=> operator
ruby: sort array of symbols ruby: sort array of symbols since symbols do not respond to the <=> method used by sort, does anyone have a technique to
How does Ruby's sort_by {rand} work? How does Ruby's sort_by {rand} work? I think this is a great Ruby one-liner: someArray.sort_by {rand} It's
Ruby Object Comparable to Fixnum Ruby Object Comparable to Fixnum I'd like to implement a class in Ruby that's comparable (using the <=> operator)
Overriding Ruby's spaceship operator <=> Overriding Ruby's spaceship operator <=> I am trying to override Ruby's <=> (spaceship) operator to sort
? @time <=> b.time : @sqn <=> b.sqn end end Tags: ruby performance sorting Your `<=>` method can also be written as: `(@time <=> b.time).nonzero? or
ruby-on-rails-3 integer @locations = Location.all.sort { |a, b| b.facebook_likes.to_i <=> a.facebook_likes.to_i } or @locations = Location.all.sort_by { |a|
model Comment belongs_to :post Tags: ruby-on-rails ruby ruby-on-rails-3 associations has_many :comments scope :active, where("active = ?", true) scope
to use it? ruby-doc example: a = [ "d", "a", "e", "c", "b" ] a.sort #=> ["a", "b", "c", "d", "e"] a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
requires Ruby 1.8.7+ Call the sort method on your hash to sort it. hash = hash.sort { |a, b| b[1] <=> a[1] } Then convert your hash to an array and extract