ruby 101 && coding dojo
DESCRIPTION
https://github.com/guiocavalcanti/ruby-101-dev-dayTRANSCRIPT
Ruby 101
Redu-dev team
Ruby 101
• A dynamic, object oriented (really) open source programming language with a focus on simplicity and productivity.
irb
• Stands for interactive ruby
• For pythonists it’s an common concept
• For Java programmers is like a bash session within the interpreter
Dynamically typed
• Types are bound to values not to variables
1 my_var = "string"2 my_var = 12
Everything is an object
• Really
1 20.to_s # "20"2 3 100.times do4 puts "100 is an object"5 end6 # "100 is an object", "100 is an object"
Dynamic language
• Some actions happens at runtime
9 class Person10 def say_hello11 "hello"12 end13 end14 15 class Person16 def say_goodye17 "goodbye"18 end19 end
21 p = Person.new22 p.say_hello23 # hello24 p.say_goodye25 # goodbye
Methods
8 def my_method(arg, arg2="default") 9 "always returning the last line"10 end
Control structures
40 result = if a > b41 "a is greater than b"42 else43 "a isnt greater than b"44 end
30 if a > b31 "a is greater than b"32 else33 "a isnt greater than b"34 end
Hashes
• For pythonists: dictionaries
• For Java programmers: associative arrays
46 concepts = { "ruby" => "programming", "learning" => "education" }47 concepts["ruby"]
Symbols
• A symbol is something that you use to represent names. What this boils down to is a way to efficiently have descriptive names while saving the space one would use to generate a string for each naming instance.
49 concepts = { :ruby => "programming", :learning => "education" }
Blocks/Procs
• Way to pass around chunks of code
51 def new_method(arg="default", &block)52 puts "the arg is: #{arg}"53 block.call54 end55 56 new_method do57 puts "Callback"58 end59 60 # the arg is: default61 # Callback
Symbols
• Usually used as hashes keys
Dojo
• With TDD (Test driven development)
• A non-sense problem to be solved collaboratively
• Tools
• RSpec
• Bundler
• RVM