70 likes | 188 Views
CS 480/680 – Comparative Languages. Ruby Odds & Ends. I/O Shortcuts. ARGV ARGF – the input stream specified on the command line Handy for file-processing scripts. Proc Objects. class JukeboxButton < Button def initialize(label, &action) super(label) @action = action end
E N D
CS 480/680 – Comparative Languages Ruby Odds & Ends
I/O Shortcuts • ARGV • ARGF – the input stream specified on the command line • Handy for file-processing scripts Odds & Ends
Proc Objects class JukeboxButton < Button def initialize(label, &action) super(label) @action = action end def buttonPressed @action.call(self) end end bStart = JukeboxButton.new("Start") { songList.start } bPause = JukeboxButton.new("Pause") { songList.pause } Odds & Ends
The Debugger • ruby –r debug script.rb • List (l) • Display (disp) • Break (b & del) • Watchpoints (w) • Continue (c) • Backtrace (where) • Help !!! Odds & Ends
The Profiler • See profiler.rb Odds & Ends
The Standard Library • Included with ruby, but you need to use ‘require’ for each library module you want to use. • Class Date • Module Find – see clean • Class File • Module Parsedate • Class Tempfile • Library Timeout Odds & Ends
Require “English” $* $ARGV $" $LOADED_FEATURES $? $CHILD_STATUS $& $MATCH $< $DEFAULT_INPUT $. $NR $> $DEFAULT_OUTPUT $, $OFS $! $ERROR_INFO $\ $ORS $@ $ERROR_POSITION $\ $OUTPUT_RECORD_SEPARATOR $; $FIELD_SEPARATOR $, $OUTPUT_FIELD_SEPARATOR $; $FS $$ $PID $= $IGNORECASE $' $POSTMATCH $. $INPUT_LINE_NUMBER $` $PREMATCH $/ $INPUT_RECORD_SEPARATOR $$ $PROCESS_ID $~ $LAST_MATCH_INFO $0 $PROGRAM_NAME $+ $LAST_PAREN_MATCH $/ $RS $_ $LAST_READ_LINE Odds & Ends