70 likes | 193 Vues
Dive into the essentials of Ruby programming with an emphasis on I/O shortcuts like ARGV and ARGF for streamlined file processing. Learn about practical implementations using the Proc Objects class in the creation of interactive Jukebox buttons, enabling play and pause functionalities. Discover powerful debugging commands such as list, display, breakpoints, and watchpoints, as well as profiling techniques to optimize your code. Additionally, explore the Ruby Standard Library, how to access various modules, and the significance of require for enhanced functionality.
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