Time to get off the Rails and learn the core foundation of the Rails Framework, Ruby. Ruby is a clean, flexible and easy to read language. During this session you will learn
basic syntax, OOP and the tools/libs the Ruby Way.
make toxic brew subject + " make toxic brew" # => Grumpy wizards make toxic brew "#{subject} make toxic brew" # => Grumpy wizards make toxic brew '#{subject} make toxic brew' # => #{subject} make toxic brew content = <<END One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little END Thursday, February 28, 13
wizards make toxic brew".reverse # => "werb cixot ekam sdraziw ypmurG" "Grumpy wizards make toxic brew".upcase # => "GRUMPY WIZARDS MAKE TOXIC BREW" "".methods # => Shows all methods available to String, too many to list ;) Thursday, February 28, 13
the greatest language EVAR!" content.sub('PHP', 'Ruby') # => "Welcome to an intro of Ruby. PHP the greatest language EVAR!" content.gsub('PHP', 'Ruby') # => "Welcome to an intro of Ruby. Ruby the greatest language EVAR!" content.gsub(/php/i, 'Ruby') # => "Welcome to an intro of Ruby. Ruby the greatest language EVAR!" Thursday, February 28, 13
# DO NOT show post end unless @user.access? # Access Denied end if [email protected]? # Access Denied end if format == 'xml' # Base output on XML elsif format == 'json' # Do some JSON Hotness end @reservation.save if @location.available? redirect_to users_path and return unless @user.save Same Conditional Thursday, February 28, 13
{ name: 'Jane', username: 'jadoe' }, { name: 'Jake', username: 'jsmith' } ] users.each do |user| puts user[:name] end users.each_with_index do |user, index| puts "[#{index}] #{user[:name]}" end user = "Random User Variable" for user in users puts user[:name] end puts user # => {:name=>"Jake", :username=>"jsmith"} User is still defined? Thursday, February 28, 13
World # => Hello World # => Hello World bottles = 99 while bottles > 0 # take one down pass it... puts bottles.to_s + " bottles of beer on the wall" bottles -= 1 end until file.eof? # Work with line content end Thursday, February 28, 13
yield(value) end self end end my_numbers = [1,2,3,4] my_numbers.square! do |element| element ** 2 end puts my_numbers.join(', ') # => 1, 4, 9, 16 Thursday, February 28, 13
I'm a Proc" }.call "Finished Proc Test" end def test_lambda lambda { return "Hey look I'm a Lambda" }.call "Finished Lambda Test" end puts test_proc # => Hey look I'm a Proc puts test_lambda # => Finished Lambda Test Y U NO FINISH? Thursday, February 28, 13
path @dimensions = [32, 20] end def width @dimensions[0] end def height @dimensions[1] end def square? width == height end end image = Asset.new('/images/hello.jpg') puts "I'm No Square" unless image.square? Thursday, February 28, 13
@path = path @dimensions = [32, 20] end def square? width == height end protected def get_type # get class type end end image.get_type # => protected method `get_type' called for #<Asset: 0x007f9ce2085508> (NoMethodError) Thursday, February 28, 13
"HTML GOES HERE" end end end class Admin::AlbumsController < ApplicationController restrict_to_permission :edit_pages, :except => [ :index, :show ] before_filter :login_required, :only => [ :index, :show ] def users ::User.findByAlbum(self.id) end end Global Namespace Thursday, February 28, 13