190 likes | 300 Views
Trends in Scripting Languages. History. For me the purpose of life is partly to have joy. Programmers often feel joy when they can concentrate on the creative side of programming, so Ruby is designed to make programmers happy. Yukihiro “Matz” Matsumoto. History. 1993
E N D
History For me the purpose of life is partly to have joy. Programmers often feel joy when they can concentrate on the creative side of programming, so Ruby is designed to make programmers happy. Yukihiro “Matz” Matsumoto
History • 1993 • Fill what lacked in Perl and Python • More powerful than Perl • More Object Oriented than Python • Facilitate creativity • 1995 – First release
Basic Syntax #example if-block if goldilocks > 10 puts “too big” elsif goldilocks < 10 puts “too small” else puts “just right” end
Basic Syntax #example function call def my_funct(arg) “Hello #{arg}” end puts my_funct(“world!”)
Example Bear Object Part 1 • Initialization • Accessor Methods • Mutator Methods
Types • Seven basic types: • numbers • strings • hashes • ranges • symbols • regular expressions
Types - Numbers num = 81 6.times do puts “#{num.class}: #{num}” num *= num end
Types - Strings • single quoted strings • double quoted strings puts ‘string \n string’ puts “string \n string”
Types - Hashes • Basically Associative Arrays • Uses {} and => notation bears = { “mamma” =>1, “pappa” =>2, “baby” =>3 } puts[“pappa”]
Types - Ranges • Inclusive ranges (‘a’..’e’) • Exclusive ranges (‘a’…’e’) • As a “Comparator” • must support comparable operator <=> • must implement the succ method
Example Bear Object Part 2 • Implementing Range support • <=> Comparable operator • succ method
Types – Regular Expressions • Pattern matching of String objects • Object of class Regexp • declared from constructor • defined directly re1 = Regexp.new(‘[a-z]’) re2 = /[a-z]/ “Goldilocks” =~ re1 “GOLDILOCKS” =~ re1
Scope of Variables • Specific syntax for declaring scope • Local within each block • Global, Instance, Class maintain their scope with their respective definition • Can use the :: operator i.e. ClassName::ConstName
Conclusion • A programmer’s language • Readability vs. Writability • Facilitate creativity?