Ruby 101 && Coding Dojo

14
Ruby 101 Redu-dev team

description

https://github.com/guiocavalcanti/ruby-101-dev-day

Transcript of Ruby 101 && Coding Dojo

Page 1: Ruby 101 && Coding Dojo

Ruby 101

Redu-dev team

Page 2: Ruby 101 && Coding Dojo

Ruby 101

• A dynamic, object oriented (really) open source programming language with a focus on simplicity and productivity.

Page 3: Ruby 101 && Coding Dojo

irb

• Stands for interactive ruby

• For pythonists it’s an common concept

• For Java programmers is like a bash session within the interpreter

Page 4: Ruby 101 && Coding Dojo

Dynamically typed

• Types are bound to values not to variables

1 my_var = "string"2 my_var = 12

Page 5: Ruby 101 && Coding Dojo

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"

Page 6: Ruby 101 && Coding Dojo

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

Page 7: Ruby 101 && Coding Dojo

Methods

8 def my_method(arg, arg2="default") 9 "always returning the last line"10 end

Page 8: Ruby 101 && Coding Dojo

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

Page 9: Ruby 101 && Coding Dojo

Hashes

• For pythonists: dictionaries

• For Java programmers: associative arrays

46 concepts = { "ruby" => "programming", "learning" => "education" }47 concepts["ruby"]

Page 10: Ruby 101 && Coding Dojo

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.

Page 11: Ruby 101 && Coding Dojo

49 concepts = { :ruby => "programming", :learning => "education" }

Page 12: Ruby 101 && Coding Dojo

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

Page 13: Ruby 101 && Coding Dojo

Symbols

• Usually used as hashes keys

Page 14: Ruby 101 && Coding Dojo

Dojo

• With TDD (Test driven development)

• A non-sense problem to be solved collaboratively

• Tools

• RSpec

• Bundler

• RVM