vs
1.methods => => [:to_s, :inspect, ...]
"a string".class => String
Vehicle.new # not new Vehicle()
1 + 2 # => 1.+(2)
cars.map(&:registration_number).reject(&:empty?).join("\n")
// the map part, in Java:
List<String> plates = new ArrayList<String>(); for(Car c: cars) { plates.add(c.registrationNumber(); }
sentence.split.reverse.join ' ' # ruby
" ".join(reversed(sentence.split())) # python
File: read, open, exists?, path
Array/Hash/any Enumerable:
numbers.all? {|number| number.odd? }
... none?, any?, none?, one?, include?
each, map, reduce, select/reject, sort/group/count, slice etc.
"It's so consistent that you start being able to guess how things will work, and you're right most of the time. It's beautiful. And fun. And practical."
- Steve Yegge
"My conscience won’t let me call Ruby a computer language. That would imply that the language works primarily on the computer’s terms."
_why
xml = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
xml.coder {
xml.name 'Matsumoto', :nickname => 'Matz'
xml.language 'Ruby'
}
# ⇒ <coder><name nickname="Matz">Matsumoto</name><language>Ruby</language></coder>
# Task: description(string), completed(boolean)
Task.find(:one, :conditions => {description: 'Attend #RailsGardenBLR'})
Task.find_by_description('Attend #RailsGardenBLR')
Task.find_all_by_completed(true)
Task.find_or_create_by_description('Go back happy!')
The goal of Ruby is to make programmers happy. I started out to make a programming language that would make me happy, and as a side effect it’s made many, many programmers happy.
- Matz
Happiness has a cascading effect. Happy programmers do the right thing. They write simple, readable code. They take clean, expressive, readable, elegant approaches. They have fun.
- DHH, 37Signals