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

Brief Ruby/Ruby on Rails intro

Brief Ruby/Ruby on Rails intro

Florian Plank

March 28, 2014
Tweet

More Decks by Florian Plank

Other Decks in Programming

Transcript

  1. I hope to see Ruby help every programmer in the

    world to be productive, and to enjoy programming, and to be happy. at is the primary purpose of Ruby language.” “
  2. - RubyGems, Bundler & Rake - Multiple implementations (MRI, JRuby,

    Rubinius, mruby, MacRuby, Topaz, …) - Solid Standard Library Ecosystem
  3. class Animal def eat(food) puts "Animal eating" end end my_animal

    = Animal.new animal.eat # => "Animal eating"
  4. … if it walks like a duck and talks like

    a duck, it’s a duck, right? So if this duck is not giving you the noise that you want, you’ve got to just punch that duck until it returns what you expect.” “
  5. class Greeter def method_missing(name, *args) name = name.to_s if name

    =~ /^hello_/ puts "Hello, #{name.gsub(/^hello_/, '')}!" else super end end end Greeter.new.hello_john # => "Hello, john!"
  6. def greet(&block) # ... greeting = yield("John") # ... end

    greet do |name| "Hello, #{name}!" end
  7. - Open Source Web Framework - MVC - Convention over

    Con guration - DRY - Opinionated Principles
  8. $ gem install rails $ rails new blog $ cd

    blog $ rails generate scaffold post title content:text $ rake db:migrate $ rails server
  9. class Account < ActiveRecord::Base # Returns all accounts with unread

    messages. def self.with_unread_messages joins(:messages).merge(Message.unread) end end