Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hello Ruby

Hello Ruby

Cadu Ribeiro

April 23, 2015
Tweet

More Decks by Cadu Ribeiro

Other Decks in Programming

Transcript

  1. Ruby ..is a dynamic, open source programming language with a

    focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. https://www.ruby-lang.org/en/documentation/
  2. Ruby Version Manager (RVM) RVM is a command-line tool which

    allows you to easily install, manage, and work with multiple ruby $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 $ curl -sSL https://get.rvm.io | bash -s stable https://github.com/rvm/rvm
  3. IRB … stands for “interactive Ruby” and is a tool

    to interactively execute Ruby expressions read from the standard input. $ irb
  4. or || && and http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/ and is useful for chaining

    related operations together until one of them returns nil or false or is useful for chaining expressions together. The best way to think about the chains constructed with or is as series of fallbacks: try this, if that fails try this, and so on. For instance:
  5. map http://railspikes.com/2008/8/11/understanding-map-and-reduce Returns a new array with the results of

    running block once for every element in enum. http://apidock.com/ruby/Enumerable/map
  6. reduce / inject http://railspikes.com/2008/8/11/understanding-map-and-reduce Combines all elements of enum by

    applying a binary operation, specified by a block or a symbol that names a method or operator.
  7. lambdas • a Proc that check the number of arguments

    • Diminutive return, in other words, a Proc return will stop 
 a method, lambdas will return their value and let the method 
 continue
  8. Exercises • Generate a Fibonacci sequence in an array until

    500 • Create a method that receives N parameter and return their sum • Create a method that receives a string and check if its a palindrome
  9. Sum

  10. Gems • What? essentially a Ruby plugin • Why? code

    reuse as open-source, it provides others the opportunity
 to contribute by adding features • How? $ gem install bundler $ bundle gem my_gem
  11. Exercise Create a GEM that performs the 4 basic math

    operations - SUM - SUBTRACTION - MULTIPLICATION - DIVISION Tip: folder already created ~/Desktop/Hello Ruby/hello_ruby_calculator