ruby and rails james crisp.net practice lead thoughtworks australia from aperspective

20
Ruby and Rails James Crisp .NET Practice Lead ThoughtWorks Australia From a perspective

Upload: dustin-basil-horton

Post on 02-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Ruby and Rails

James Crisp .NET Practice Lead

ThoughtWorks Australia

From a perspective

James Crisp

Runtimes MRI

IronRuby Console Demo

public class CSharpDemo : Demopublic class CSharpDemo : Demo{{

public void SayHello()public void SayHello(){{

for (int i=0; i<5; i++)for (int i=0; i<5; i++){{

Console.WriteLine(“Hi from C#!”);Console.WriteLine(“Hi from C#!”);}}

}}

public IEnumerable<string> Greet(public IEnumerable<string> Greet(IEnumerable<guest> guests)IEnumerable<guest> guests)

{{return guests.Select(g => “Welcome” return guests.Select(g => “Welcome”

+ g.Name);+ g.Name);}}

}}

class class RubyDemoRubyDemo < < DemoDemodef def say_hellosay_hello

5.times { puts “Hi from Ruby!” }5.times { puts “Hi from Ruby!” }endend

def def greet(guests)greet(guests)guests.collect { |g| “Welcome #{g.name}” }guests.collect { |g| “Welcome #{g.name}” }

endendendend

>> RubyDemo.new.greet(fred, tina)>> RubyDemo.new.greet(fred, tina)=> [“Welcome Fred”, “Welcome Tina”]=> [“Welcome Fred”, “Welcome Tina”]

Tools and Frameworks

c:\> gem install railsc:\> gem install rails

desc “Generate application code”desc “Generate application code”task task :code_gen:code_gen do do # do the code generation# do the code generationendend

desc “Compile code”desc “Compile code”task task :compile => [:code_gen]:compile => [:code_gen] do do #do the compilation#do the compilationendend

desc “Test application”desc “Test application”task task :test => [:compile]:test => [:compile] do do # run the tests# run the testsendend

Rake

Capistrano

desc "Start ferret server"desc "Start ferret server"task task :start, :role => :app:start, :role => :app do do run "cd #{current_path}; script/ferret_server -e #{stage} start"run "cd #{current_path}; script/ferret_server -e #{stage} start"end end

desc "Stop ferret server"desc "Stop ferret server"task task :stop, :role => :app:stop, :role => :app do do run "cd #{current_path}; script/ferret_server -e #{stage} stop" run "cd #{current_path}; script/ferret_server -e #{stage} stop" endend

RSpec

describedescribe User do User do

itit "should be in any roles assigned to it" do "should be in any roles assigned to it" do user = User.newuser = User.new user.assign_role("assigned role")user.assign_role("assigned role") user.user.should beshould be__in_role("assigned role")in_role("assigned role") endend... ... end end

Routing Table

Controller Method

Model View

Rails ProjectDemo

See also...Rails & screencasts http://rubyonrails.org

Ruby / Rails APIhttp://gotapi.com

John Lam's blog for Iron Rubyhttp://www.iunknown.com/

Slides for this talkhttp://www.jamescrisp.org

http://upload.wikimedia.org/wikipedia/en/2/27/Microsoft_.NET_Logo.png - .net logohttp://en.wikipedia.org/wiki/Image:Ruby-(programming-language)-logo-2008.pnghttp://www.pragprog.com/images/covers/original/rails3.jpg – agile development with railshttp://flickr.com/photos/rrrodrigo/2394122680/ - Matzhttp://flickr.com/photos/maguisso/1028956186/ - Ruby bookhttp://media.xircles.codehaus.org/_projects/jruby/_logos/medium.png – JRuby logohttp://www.atdot.net/yarv/ - YARV logohttp://www.ironruby.net/@api/deki/site/logo.png – IronRuby logo

Image References

Questions?