Download presentation
Presentation is loading. Please wait.
1
Ruby Testing 2, 11/9/2004
2
What is Ruby? Scripting language, developed by Yukihiro “Matz” Matsumoto Current version = 1.8
3
Ruby Documentation Pickaxe book (shown last class)
ri command ri <Class name> Ruby Cheat Sheet (on blackboard)
4
Running Ruby Command line Eclipse SciTE irb ruby –w <file name>
More later SciTE Demo irb
5
Ruby in Eclipse Download Ruby Development Tool from Nowhere near the functionality of Java in Eclipse In preferences, set path to ruby bin directory
6
Ruby Basics Everything is an object
Comments start with # and go until end of line Methods are created using def…end
7
Ruby Naming Initial letter Multi-word names End characters
Local variables, method parameters, and method names lowercase letter or underscore Global variable $ Instance variable Class variable Class names, module names, constants uppercase letter Multi-word names Instance variables separate words with underscores Class names use MixedCase End characters ? Indicates method that returns true or false to a query ! Indicates method that modifies the object in place rather than returning a copy
8
Blocks Allow passing chunks of code in to methods
Single line blocks enclosed in {} Multi-line blocks enclosed in do…end Receiving method uses “yield” command to call passed code (can call yield multiple times) Can use parameters [ 1, 3, 4, 7, 9 ].each {|i| puts i }
9
Strings in Ruby Quotes matter!
Strings in “” (double quotes) have replacement processing on them \<char> replacement (like C -- \n = newline, etc) Expression replacement (“Variable x = #{x}” would have the value of x substituted for the #{x}) Strings in ‘’ (single quotes) are treated as literals with no processing Strings in `` (back ticks) are treated as commands to be executed by the operating system
10
Control structures If…elsif…else…end unless <condition> … end
while <condition>… end until <condition>… end case when <condition> then <value>… else… end #.times (e.g. 5.times()) #.upto(#) (e.g. 3.upto(6)) <collection>.each {block}
11
Ruby equivalents in Java
null toString() extends constructor name = class name try…catch import Ruby nil to_s < constructor name = initialize begin…end…rescue require
12
Test::Unit Very similar to JUnit require ‘test/unit’
Class MyTestClass < Test::Unit::TestCase Use “flunk” instead of JUnit’s “fail”
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.