Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE4102/5102 Team Project Ruby & Ruby on Rails

Similar presentations


Presentation on theme: "CSE4102/5102 Team Project Ruby & Ruby on Rails"— Presentation transcript:

1 CSE4102/5102 Team Project Ruby & Ruby on Rails
Savanna Smith, Samantha Gustafson

2 Motivation Ruby provides … Readability
Helpful conventions for ease in development. Exemplifies language paradigms Flexibility Users can add their own methods to Ruby’s base code so it runs in a way that is specific to their needs.

3 Biography - Yukihiro Matsumoto
Self taught programmer Information science degree from University of Tsukuba in Japan Worked at netlab.jp when he came up with the idea for a powerful scripting language that was also object-oriented (aka Ruby) He currently works at Heroku as Chief Architect of Ruby and Technical advisor at VASILY, Inc. took out other slides because it seemed like acknow and trivia were only for long ppt.

4 Biography - David Heinemeier Hansson
Danish programmer and founder of Ruby on Rails Business administration and computer science degree from Copenhagen Business School Hansson created a web-based project tool for Basecamp (previously 37signals) Used Ruby to develop a unique framework for this project, which he later released in 2004 as Ruby on Rails

5 History of Ruby 1993 simple, portable, object-oriented.
iterators and closures exception handling and garbage collection. 2003, version 1.8 duck-typing fully-qualified names, UNIX commands, and many other features. 2007 Mac OS X ships with Ruby 2008, version 1.8.7 Ruby was at its peak. Today, version 2.5.0

6 History of Ruby on Rails
2004 Released as an open source project. 2007 Apple shipped out Mac OS X with Rails included. 2009, version 2.3 New developments in engines, templates, Rack and nested model forms. 2008 Web app framework Merb was released. Rails to include best parts of Merb in Rails 3.0. Today, version 5.1 Included JavaScript.

7 Language Paradigm Primarily object-oriented
encapsulation, polymorphism, inheritance, and classes But Ruby also supports imperative, functional, and reflective paradigms Allows users to code in whatever style they prefer, instead of forcing them to adapt to one style

8 Functional Programming
Higher-order function: takes a function or returns one. First-class function support: When a language can handle those actions. Functional programming requires that no states are changed when a function is run — we simply use the output of those functions. Side effects: anything a function does to the rest of the program besides taking input and returning output. Referential transparency: The ability to replace a function call with its resulting value. Function composition: Combining two or more functions at once. terms

9 Repositories/Libraries
Packet manager is RubyGems A “gem” is a package that can be installed from the command line Most gems are libraries, but there are a few that are applications Over 9000 gems available on RubyGems.org

10 IDEs RadRails (from Aptana) is a rapid application development IDE
It provides developers everything they need to design, test and execute their applications RadRails was built on the Eclipse RCP, meaning RadRails tools are also available as Eclipse plug-ins.

11 IDEs RubyMine (from JetBrains) provides coding assistance, code refactoring, and code analysis capabilities It has built-in consoles, automatic Ruby Gems management and Rake support

12 Ruby Syntax Everything is an object in Ruby
Syntax is similar to others we’ve learned, +, -, *, / = is assignment operator == is comparator operator === case equality Comments are denoted as ‘#’

13 Ruby STDIN/STDOUT print: prints to screen
puts: also prints but followed by a new line gets: first checks ARGV, then checks STDIN STDIN.gets: takes input only from STDIN print “hello world” print “goodbye” puts “hello world” puts “goodbye” puts “enter value:” val = gets puts val hello worldgoodbye hello world goodbye enter value: 14

14 Ruby File I/O File.new : creates file File.open : opens file
fp = File.new(“filename”, “mode”) # ... process the file fp.close File.open : opens file File.open(“filename”, “mode”) Common modes: “r” : read “w” : write File.rename : renames file File.rename(“oldname.txt” “newname.txt”) fp.write( ) : writes to file fp.write(“word count”)

15 Variables (cont.) local variable var instance variable @var
class variable global variable $var constant (begins with uppercase letters) VAR

16 Methods Definitions Simple method definition (ex. line 1)
Method with argument (ex. line 5) Method with multiple arguments (ex. line 9).

17 Method Return Methods return one object (ex. line 1)
They return the value of the last evaluated statement Can also use “return” statements (ex. line 5) Can get around the lack of multiple returns For example, the method starting on line 12 actually returns the array: [1, “this is a multiple return!”]

18 Control Flow Conditional statements if, elsif, else, case, unless
Unconditional Loops loop, break, next

19 Control Flow (cont.) Conditional Loops while, until
Looping over list of values for, in Iterators

20 Classes Can add methods to a class and create a constructor
To create a new class object, call “.new” Example:

21 Classes (cont.) Instance Methods vs. Class Methods
Use instance methods on a particular instance of the class Use class methods when a functionality belongs to that class and not to any one instance. Example:

22 Classes - Inheritance Inheritance is a key organizational technique for Rails No multiple inheritance

23 Introspection and Reflection
self keyword: references the current object. Introspection: examine an object’s type at runtime. Reflection: examine and modify the structure and behavior of a program at runtime. invoke a method on an object, instantiate a new object, modify an attribute of an object, all without knowing the names of the interfaces, fields, methods at compile time.

24 Modules Modules allow grouping methods, classes, and constants
provide a namespace prevent name clashes implement the mixin facility which eliminates the need for multiple inheritance Example:

25 Functional Programming (cont.)
Lambdas allow us to store a function inside of a variable. A Proc is a block — a series of commands that can be executed Lambdas and Procs return to the method from which they were called. Procs are blocks and not methods so they will end the entire process they are inside.

26 Rails First you have to set up “behind the scenes” structures
skeleton of application, web server, database, etc. > rails new library > Rails server > create database db_name In file ending in “.html.erb” you can format the look using some HTML practices <h1> this is a header </h1> <p> this is text on the page </p> Rails provides a standard structure for web apps, so common patterns are done for you Rails is succinct which leads to productive development

27 Word Frequency Code (FileIO)
total_count = 0 WORDS_COUNT = {} File.readlines("platest1.txt").each do |line| words = line.downcase.split words.each do |word| word = word.gsub(/[,.()'"]/,'') if WORDS_COUNT[word] WORDS_COUNT[word] += 1 else WORDS_COUNT[word] = 1 end fp = File.open('output.txt','w') WORDS_COUNT.each do |key,value| total_count+=value fp.write("#{key} = #{value}\n") fp.write("total count = #{total_count}") fp.close output.txt: cse4102 = 1 programming = 2 language = 2 assignments = 1 pla = 1 due = 5 dates = 1 ... new_u_words_min = 1 these = 1 have = 1 added = 1 shown = 1 below = 1 number = 1 last = 1 total count = 624 repl.it/PresentationRubyExample

28 Word Frequency Code (stdin/stdout)
total_count = 0 WORDS_COUNT = {} $/ = "ENDS" print "enter text: " line = STDIN.gets words = line.downcase.split words.each do |word| word = word.gsub(/[,.()'"]/,'') if WORDS_COUNT[word] WORDS_COUNT[word] += 1 else WORDS_COUNT[word] = 1 end WORDS_COUNT.each do |key,value| total_count+=value puts "#{key} = #{value}" puts "total count = #{total_count}" cse4102 = 1 programming = 2 language = 2 assignments = 1 pla = 1 due = 5 dates = 1 ... these = 1 have = 1 added = 1 shown = 1 below = 1 number = 1 last = 1 ends = 1 total count = 625 repl.it/PresentationRubyExample

29 Conclusion Ruby and Ruby on Rails is great to learn, especially for its ease of use and object-oriented and functional paradigms. Sites created with Rails Airbnb Github Bloomberg and more! Hulu Twitch Urban Dictionary


Download ppt "CSE4102/5102 Team Project Ruby & Ruby on Rails"

Similar presentations


Ads by Google