Machine Learns

Mar 5, 2012    |      0 comments

Setting up .sort function to your custom class in RUBY


class Eren
include Comparable
attr_accessor :age


def initialize _age
@age = _age
end


def <=> other
self.age <=> other.age
end
end


e1 = Eren.new(10)
e2 = Eren.new(11)
e3 = Eren.new(2)


d = [e1,e2,e3].sort!
d.each do |x|
puts x.age
end

Share

Related posts:

  1. Use yield in Ruby
codingexampleruby

Tags

AI algorithm C code codebook coding command computer computer security computer vision C programming CUDA deeplearning deep learning documentary example facts git github hack hacking hackthissite installation internet Java linux machine learning neural network paper review presentation programming python quora random forests research research notes ruby solution talk technology ted tts tutorial video what is
  • E-mail
  • RSS

Created by Site5 WordPress Themes. Experts in WordPress Hosting