language - Everything is an object - Weakly typed (“duck type”) - No semicoloms ; - Parenthesis can be omitted - Implicit returns - Syntax reads like English - Friendly Community - Lots of Resources - Awesome standard library - Designed to be fun 5
do desc "run Javascript tests" task :javascript do exec 'yarn run test' end end # Commands rake -T | grep javascript rake test:javascript # run Javascript tests rake test:javascript
over configuration - Hides stuff you do not need to know - Eliminates tedious tasks - Console - Command line utilities - Database abstraction - Scaffolding for CRUD - Active Record - Security concerns - (SQL Injection, XSS, CSRS tokens) - Active Record - Migrations - devs can change db independently without stepping into each other’s toes - Full stack - MVC - It helps you to become a better programmer - ~14 years old - Everyone wants to be rails 11
# puts num end # Alternative one-liner: numbers.each { |num| puts num } # with index numbers.each_with_index do |num, index| # puts "#{num} @#{index}" end // PHP foreach ($numbers as $num) { // echo $num; } // with index foreach ($numbers as $index => $num) { // echo "$num @$index" }
the one', 'three' => 'None of the above', } hash[:one] # 'the one' hash['three'] # ‘None of the above’ hash['non-existing'] # nil hash.fetch('non-existing') # raises error hash.fetch('non-existing', 'default') # 'default' hash.each do |key, value| p "#{key} has value #{value}" end hash.key?(:one) # true hash.include?(‘The One’) # true
puts "Hello world" } 10.times { |n| puts "Hello world ##{n}" } 1.upto(10) { |n| puts "Hello world ##{n}" } until fished # do stuff end while !fished # do stuff end loop do # do stuff, same as while true end
attr_reader :age def initialize(name, age) @name = name @age = age end end class FlexiblePerson < Person def name=(new_name) @name = new_name end end someone= Person.new('Bob') someone.name # Bob someone.name = 'someone' # raises error 'undefined method...' someone_else = FlexiblePerson.new('Bob') someone_else = 'Not Bob' someone_else.name # Not Bob
Undeniable history of fun Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. It was designed to be fun... 37 No Yes International Institute of Fun