Getting started with ruby

Getting started with ruby

A lightning talk for Eindhoven.rb about getting started with various command-line options for the ruby program.

241eb3a089132c5a0c65e765558a6735?s=128

Arjan van der Gaag

April 06, 2012
Tweet

Transcript

  1. 5.
  2. 9.

    $ ruby app.rb $ ruby -r “mylib” app.rb $ ruby

    -rubygems app.rb $ ruby -I lib app.rb
  3. 10.

    # lib/post.rb class Post attr_accessor :title, :author end # app.rb

    require "post" get '/' do @posts = Post.all erb :index end $ ruby -rubygems -r sinatra -I lib app.rb
  4. 11.
  5. 21.

    $ ruby -e ‘puts “Hello, world”’ $ ruby -n app.rb

    $ ruby -p app.rb $ ruby -lpe app.rb
  6. 23.

    $ ruby -e ‘puts “Hello, world”’ $ ruby -n app.rb

    $ ruby -p app.rb $ ruby -lpe app.rb
  7. 24.

    $ ruby -e ‘puts “Hello, world”’ $ ruby -n app.rb

    $ ruby -p app.rb $ ruby -lpe app.rb $ ruby -pe “next unless /<{7}/../>{7}/” conflicted_file
  8. 25.

    $ ruby -e ‘puts “Hello, world”’ $ ruby -n app.rb

    $ ruby -p app.rb $ ruby -lpe app.rb $ ruby -pe “next unless /<{7}/../>{7}/” conflicted_file $ ruby -an -F, -e ‘puts $F[0]‘ csv_file
  9. 27.

    $ ruby -e ‘puts “Hello, world”’ $ ruby -n app.rb

    $ ruby -p app.rb $ ruby -lpe app.rb $ ruby -pe “next unless /<{7}/../>{7}/” conflicted_file $ ruby -an -F, -e ‘puts $F[0]‘ csv_file
  10. 28.

    $ ruby -e ‘puts “Hello, world”’ $ ruby -n app.rb

    $ ruby -p app.rb $ ruby -lpe app.rb $ ruby -pe “next unless /<{7}/../>{7}/” conflicted_file $ ruby -an -F, -e ‘puts $F[0]‘ csv_file $ ruby -i -p -e ‘$_.downcase!’ file
  11. 29.

    #!/usr/bin/env ruby -w # Example input: # # john,secret #

    graham,test require 'digest' while line = ARGF.gets("\n") do parts = line.split ',' next unless parts[1] print line.gsub parts[1], Digest::SHA1.hexdigest(parts[1]) end
  12. 30.
  13. 31.

    # Read all values in ARGV as files as #

    a single stream OR read from STDIN puts ARGF.read puts $<.read
  14. 32.

    - $/ input record separator (default \n) - $\ output

    record separator (default \n) - $, output field separator (default nil) - $; input field separator (default nil) - $_ current line - $. number of current line - $F result of $_.split($;) Ruby globals
  15. 33.

    - OptParse - StrScanner - OpenStruct - Set - CSV

    - Find - FileUtils - Tmpfile - Zlib - Abbrev Know your StdLib
  16. 34.
  17. 35.