ruby杂记

ruby基本类中的方法:puts Object.private_instance_methods

 范围:

a=1..20
puts a.min
puts a.max
puts a.reject{ |i| i< 15}
puts a.select{ |i| i< 15}
a.each do |i|
  print i.to_s+", "
end

 HASH

hash={
    "name" => "xiaoming",
    "age"  => 18,
}
person=Hash.new
puts "Num is :"+person.size.to_s
person['name'] = "xiaoming"
puts "Num is :"+person.size.to_s

print hash.keys()
puts
puts hash.include?('name')
hash.delete('name')
puts hash.has_key?('name')
print hash.values


hash={
    "name" => "xiaoming",
    "age"  => 18,
}
puts" each, each_key, each_value, eack_pair"
hash.each do |key, value|
  puts "key: "+key.to_s+"  value: "+value.to_s
end

 

posted on 2016-09-20 10:00  lly001  阅读(138)  评论(0编辑  收藏  举报

导航