Learning Ruby - 14 Grabbag IV - the fourth installment of the Trilogy.

Slides:



Advertisements
Similar presentations
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Advertisements

Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
And other languages….  Writing programs that write programs (cool!)  Often used to create domain-specific languages (DSL) You’ve all heard of at least.
Ruby (on Rails) CSE 190M, Spring 2009 Week 3. Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins.
All Programming is Metaprogramming (Engineering Software as a Service §3.5) © 2013 Armando Fox & David Patterson, all rights reserved Based on materials.
Language of the Month If it’s December, it must be Ruby! Adam Coffman and Brent Beer.
4.1 Reading and writing files. 4.2 Open a file for reading, and link it to a filehandle: open(IN, "
Learning Ruby Ruby Code Blocks. Code blocks in Ruby are not like “blocks of code” in other programming languages Blocks are typically associated with.
Learning Ruby - 5 Files. while line = gets puts line end while line = gets puts line.downcase end while line = gets puts line.downcase if line =~ /UP/
Learning Ruby - 13 Grabbag III - The Return of the Grabbag.
Learning Ruby - 7 Methods. def addem ( first, second ) first + second end # of addem. addem( 23, 6 ) def addemall ( first, *rest ) rest.each { |r| first.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
CS 142 Lecture Notes: RubySlide 1 Basic Ruby Syntax sum = 0 i = 1 while i
Learning Ruby - 4 Ruby Code Blocks. Pay Attention - This is important! Code blocks in Ruby are not like “blocks of code” in other programming languages.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Learning Ruby - 6 Regular Expressions. Ruby's Regex Technology Specifying what you are after using a terse, compact syntax Very useful when working with.
CS 31 Discussion, Week 6 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
Stuff about DX/GS. Overview Installation of client/server packages 1 Complex installation: pydxs (pydxc) package into …/lib/python2.4/site- packages/
Basic Programming in Ruby Today’s Topics: Introduction last class irb history log Methods Classes (briefly) Using 3 rd Party Libraries rubygems ‘ require.
Also “open class” and other languages….  A module is a named group of methods, constants, and class variables  All classes are modules  Modules are.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
Learning Ruby - 10 Exploiting Classes. Ruby's Class Library Array - an ordered collection of objects Bignum - really big integer values Binding - remembering.
ProgLan Python Session 4. Functions are a convenient way to divide your code into useful blocks, allowing us to: order our code, make it more readable,
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Dean Anderson Polk County, Oregon GIS in Action 2014 Modifying Open Source Software (A Case Study)
CSI 3125, Preliminaries, page 1 Compiling the Program.
Guide to filenames. FilenameTopic RubyBasicsExpressions, strings, etc.
CS2021 Python Programming Week 3 Systems Programming PP-Part II.
CS 142 Lecture Notes: RubySlide 1 Basic Ruby Syntax sum = 0 i = 1 while i
Learning Ruby Classes. Variables Variables in Ruby can contain data of any type. You can use variables in your Ruby programs without any declarations.
Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz.
Shell Scripting What is Shell Programming? Putting UNIX commands in a file Seldom used where speed is important Often used to manipulate files To create.
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
Creating and Using Modules Sec 9-6 Web Design. Objectives The student will: Know how to create and save a module in Python Know how to include your modules.
JUnit Testing Why we do this and how we can get better.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Tips. Iteration On a list: o group = ["Paul","Duncan","Jessica"] for person in group: print(group) On a dictionary: o stock = {'eggs':15, 'milk':3, 'sugar':28}
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Part VI: Mapping URLs.
IndexedListWithIteratorsViaLinear1Ind
Ruby Getting started & Ruby.New Presented by Mario Tayah
Lecture 2 Python Basics.
Ruby Classes, Modules & Mixins
CSE 341 Section 9 Nick Mooney Spring 2017
Recitation – Week 8 Pranut jain.
Please use the top of the slide. The area that will be printed is 4
Perl A simple test.
Embedding the Reporting Engine Version 3.5
Specifying, Compiling, and Testing Grammars
Basic Ruby Syntax sum = 0 i = 1 while i <= 10 do sum += i*i
Basic Ruby Syntax sum = 0 i = 1 while i <= 10 do sum += i*i
Substitution in string value
CSE 341 Section 9 Winter 2018 Adapted from slides by Eric Mullen, Nick Mooney, Nicholas Shahan, Cody Schroeder, and Dan Grossman.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Passing Parameters by value
Problem Solving: Structure Charts
Nicholas Shahan Spring 2016
G. Pullaiah College of Engineering and Technology
Functions.
Lecture 12 Non-Regular Languages
CSE 341 Section 9 Fall 2017 Adapted from slides by Nick Mooney, Nicholas Shahan, Cody Schroeder, and Dan Grossman.
Introduction to Computer Science
General Computer Science for Engineers CISC 106 Lecture 03
Python Lessons 13 & 14 Mr. Husch.
Basic Ruby Syntax sum = 0 i = 1 while i <= 10 do sum += i*i
CISC101 Reminders Assignment 3 due today.
File Handling.
Keyword Arguments aka Named Parameters in Ruby (and Python)
Challenge Guide Grade Code Type Slides
Presentation transcript:

Learning Ruby - 14 Grabbag IV - the fourth installment of the Trilogy

Creating Iterators Adding iterator support (that is,.each,.collect,.inject, etc., etc.) is easy Simply mixin the Enumerable class into your class Use include Enumerable near the top of your class code Create an each method that makes sense for your class

class Ethernet include Enumerable def each end # of each.... end # of Ethernet. Ethernet.each

string_of_lines = IO::read( "/etc/passwd" ) array_of_lines = IO::readlines( "/etc/passwd" ) Slurping Files

# Remember: all arguments are passed in as strings! ARGV.each { |arg| puts arg } option1, option2 = ARGV.collect { |arg| arg } if ARGV.length == 0 fail "Please supply some parameters!" end # of if. Processing Command-line Args

ENV.keys.each { |key| print "#{key} -> ", ENV[key], "\n" } ENV.collect() do |key, value| print "#{key} --> #{value} \n" end # of do require 'rbconfig' include Config CONFIG.keys.sort.each do |key| print "#{key} -> ", CONFIG[key], "\n" end # of do. Environments and Configurations

ruby -e 'puts $:' /usr/local/lib/site_ruby/1.8 /usr/local/lib/site_ruby/1.8/i486-linux /usr/local/lib/site_ruby/1.8/i386-linux /usr/local/lib/site_ruby /usr/lib/ruby/1.8 /usr/lib/ruby/1.8/i486-linux /usr/lib/ruby/1.8/i386-linux. Where Are My Modules?

More... Ruby So Far Look for ways to do cool stuff with Ruby. For example: A project proposal for 4 th Year: Create a Ruby extension that allows for the manipulation of the Torque Game Engine from within any Ruby program.