Title: Jim Fawcett CSE686
1Jim FawcettCSE686 Internet ProgrammingSummer
2006
Ruby And Ruby on Rails
2References
- Brown-Bag Seminar Presentation, Beyond Java
Chapters 4 and 5, Jim Fawcett, Spring 2006 - Brown-Bag Seminar Presentation, Beyond Java
Chapters 6 and 7, Taylan Yamliha, Spring 2006 - Beyond Java, Bruce Tate, OReilly, 2005
- Programming Ruby, Dave Thomas, PragmaticProgrammer
, 2005 - Agile Web Development with Rails, Dave Thomas,
David Hansson, PragmaticProgrammer, 2005
3A Useful Definition for this Presentation
- Spin from WordReference.com
- A distinctive interpretation (especially as used
by politicians to sway public opinion) the
campaign put a favorable spin on the story. - When spun, your job is to
- Listen, but be somewhat skeptical
- Make up your own mind
4Some Spins
- Bruce Tate - Author of Beyond Java
- Java is nifty, but growing too complex for a lot
of the jobs we need to do. Enter Ruby? - Kanat Bolazar one of my Ph.D. candidate advisees
- Java is nifty, has lots of tools that let me do
interesting research. I love it! Im skeptical
of what the author says. - Jim Fawcett - pragmatist
- Windows world is where most of the jobs are.
There are lots of interesting, but complicated,
technologies to use there. But windows
development isnt the only game in town Its just
the one I have most interest in. - I think the author is smart, has lots of
interesting things to say, and will give us a
view into another world, if we let him.
5(No Transcript)
6Chapter 4 Glass Breaking
- Javas new job description
- Early use to develop quick applications
- Then moved server-side
- Web site applications
- Enterprise Systems
- Mapping objects into relational model
- Distributed transactions
- Messaging middleware
- Java is flexible, so its been able to accommodate
these changes.
7Typical Requirements
- Good fit to middleware development because of its
existing packages - Servlets and web programming is not as productive
as PHP - Java just isnt very good for the simplest and
most typical applications. - Better alternatives exist for XML processing.
Javas strings are too verbose. - Natural fit to large enterprise projects due to
its libraries and large number of Java developers.
8The Learning Curve
- Most Java-based web applications use Java Server
Pages (JSP) technology, probably through Tomcat. - There are more steps, now, in using Tomcat, which
take longer to learn. - But thats not all. Youll need to understand
- Ant build and deploy web applications
- Tapestry or Struts organize user interface code
- Hibernate object relational mapper
- Spring organize application resources and
support testing
9Resources
- See the End Notes for summaries of
- PHP Hypertext PreProcessor
- JSP Java Server Pages
- J2EE Java, Enterprise Edition
- EJB Enterprise Java Beans
- Apache Apache web server
- Tomcat Containers for Java Server Pages
- Struts Model-View-Controller application
management - Tapestry Simpler MVC application management
- Spring Frmwrk Framework for building containers
of Java Server Pages - BeeHive Builds object model on top of J2EE and
Struts - Hibernate Object-Relational mapper
- Ibatus Data mapper framework
- Maven Manage build, reporting, and documentation
10Java for the Typcial Application
- For the basic problem, a web-based user interface
for a relational database, you have to learn a
lot more today than you did five years ago. - The advanced frameworks will drive the Java
language away from the base that made it popular
11Agile Development
- Simplicity
- Use the simplest thing that will work
- Automated Unit Testing
- Junit framework is recommended
- Shortened Iterations
- Shorter schedules, better integration of customer
feedback, and smaller iterations
12Development Processes Java
- Javas community and tools provide excellent
support for agile programming - Java is not such a good language for agile
development - Not the simplest language
- Not friendly to very short iterations
- Because of the need for frameworks (implied)
13Basic Java Limitations
- Frameworks make experienced Java developers more
productive but make a steep learning curve for
new developers. - Compile-time type checking adds safety at the
cost of additional time and syntax. - Java is not able to express structured data
leading to over-dependence on XML. - Javas many compromises, like primitives
(different than user types) make Java harder to
learn and more complex to write. - Java is nowhere near as dynamic as Smalltalk and
Ruby. - Javas long compile/deploy cycle is much longer
than interpreted, dynamic alternatives.
14Alternatives
- Are the Java community and large code base worth
sacrificing the productivity of other
alternatives? - The waters are rising.
- A clean, dynamic language could gain footing in
the gap between Visual Basic (6.0) and Enterprise
Java. - The lions share of Java development, even in the
enterprise, is not full of distributed
transaction and backbreaking loads. - Developers want a way to baby-sit a big
relational database with a web-based user
interface.
15Chapter 5 Rules of the Game
- Portability
- Must have a virtual machine for
- Security, portability, extensibility,
interoperability - Internet Focus
- The internet has two interfaces, for people and
machines. - The next language should build better interfaces
more easily, using a component model. - It should deal with XML productively and
efficiently. - Enterprise Integration
- The next language will should interoperate with
the existing code base. - Database Integration
- The language should access relational data in a
natural, productive way. - Transactions and Security
- Needs to integrate with existing enterprise
security frameworks.
16Generating Buzz
- Technically superior languages have failed
because they didnt generate buzz. - Walter Brights D is probably superior to C,
but its generating little interest among the
developer community. - Without buzz there is no community
- Now is a good time for a new language
- Open source software makes it easier for smaller
companies to become a force by virtue of numbers. - Web services and other protocols make it easier
to interoperate between languages. - A JVM (or CLR) can support other languages.
- But generating buzz is more art than science, and
perhaps more luck than art.
17Necessary Ingredients
- Economics
- Someone has to pay the check, and superior
productivity makes that likely. - Approachability
- New language needs to grab new users quickly to
prosper. - You should be able to get started quickly, and
solve a problem that is important to you quickly. - C was approachable because you could solve
low-level problems with a high-level language. - C was approachable because you could add C
features to C, as you needed them. - Java was approachable because the syntax was
familiar and it had a clear path to internet
applications. - The killer App
- A language needs an active community to prosper.
- A killer application can quickly draw new users.
- Applets and servlets did that for Java.
18Language Features
- Dynamic typing
- Static typing promotes safety through
compile-time checks, at the cost of productivity. - Dynamically typed languages are easier to explore
and build prototypes. - Code blocks
- Code blocks are anonymous functions that are used
to quickly assemble callbacks, provide thread
processing, and do repetitive operations on
databases and collections. - Theyre useful anywhere you need a once-only
small function, and thats lots of places. - They also reduce the remoteness factor.
- The function body is defined right where it is
used. - Continuations
- Saved stackframe hierarchies re-applied to go
back to a prior state. - Purported to be very useful for supporting
backtracking in the stateless web model. - Rapid feedback
- Reduce the time between making a change and
seeing the result. - The interpreted languages Smalltalk, Lisp, Perl,
Ruby, and VB 6.0 all have rapid feedback and are
very productive languages.
19More Language Features
- User Interface Focus
- User interface focus demands more than Java has
to give. - Dynamic Class Model
- A Java successor should be much more dynamic and
reflexive. - Javas reflection API is verbose, partly because
of the distinction between primitives and user
types. - It has to deal differently with primitives,
arrays, and classes. - Tate gives two examples where a dozen lines of
Java code are replaced with one or two lines of
Ruby code. - With Ruby you can also change classes, at
runtime, on the fly. You can change a method on
an object and leave the class untouched. Also,
interceptions are childs play. - Sound Foundations
- The next language should be object oriented and
purer than Java. - Here, the author means that primitives are first
class objects. - Consistency is important.
- Languages with consistent naming and behavior are
far easier to learn.
20Potential Suitors
- Perl
- Productive scripting language
- Write only language with cryptic syntax
- Python
- A successful dynamic programming language, close
to Ruby in syntax and power and supports the
specified features. - Syntax depends too much on white space.
- Has weak web development tools.
- Ruby
- Object oriented dynamic language, created in
Japan, and just now becoming popular in US - Beautiful syntax that stays out of your way.
- Highly dynamic
- Educated core of Ruby community works hard to
produce clean, simple APIs. - Has strong web frameworks, good support for XML
and web services. - Ruby has a couple of high profile frameworks,
like Ruby on Rails. - Ruby has good commercial backing in Japan, but
not in US. - JVM support is immature, though improving rapidly.
21More Suitors
- PHP
- Scripting language.
- Start with html and mark up with tags for
scripted actions with databases and request and
response objects. - Easy to understand and learn.
- Good for controlling a database from a web page.
- Technically awful
- Couples user interface and database together.
- Method names are inconsistent.
- C and .Net Languages
- C is a Java clone with many of the same benefits
and drawbacks. - Microsoft languages are a closed ecosystem. They
succeed or fail with the Microsoft platforms,
rather than on their own merits. - Smalltalk
- Never caught on commercially, despite attempts by
IBM as late as 1995. - Hughly productive, slightly awkward, and quirky
to the extreme. - Clean object model, incredible expressive power,
and an intelligent design and community. - Not seen as a credible alternative.
- It just wasnt ever approachable enough.
22A Random Quote from the Web
- I've been developing web apps for years, in both
PHP and Java. You really notice how much stuff
is repeated and unnecessary. How many times do
you enter the same variable or field name in the
database, in the classes, in the HTML/view? It's
a waste of time.I had developed some helper
utilities that are basically a crude form of
ActiveRecord (a Ruby on Rails construct). I
used to do a lot of Java development. J2EE
_at_. Servlets, entity beans, etc. The amount
of garbage you have to go through just to get
something deployed made me angry.Seeing Rails
was wonderful. It was all my "good ideas"
implemented cleanly with none of the PHP hacks or
Java verbosity. - NoteThere are many quotables about Ruby on
Rails that are favorable, and many that are not.
23Next UP
- Chapter 6 - Ruby in the Rough
- Chapter 7 Ruby on Rails
24End Notes Chapters 4 and 5
- PHP, JSP, Java Beans, EJB, J2EE
- Apache, Tomcat, Spring Framework
- Struts, Tapestry
- BeeHive, Hibernate, IBatus
- Maven
25PHP - http//us3.php.net/manual/en/introduction.ph
p
- (recursive acronym for "PHP Hypertext
Preprocessor") is a widely-used Open Source
general-purpose scripting language that is
especially suited for Web development and can be
embedded into HTML. - Simple answer, but what does that mean? An
example - Example 1-1. An introductory examplelthtmlgt
ltheadgt lttitlegtExamplelt/titlegt
lt/headgt ltbodygt lt?php echo "Hi,
I'm a PHP script!" ?gt
lt/bodygtlt/htmlgt
26JSP - http//www.webdevelopersjournal.com/articles
/jsp_build.html
- If you've ever used Microsoft's very popular
Active Server Pages (ASP) then you'll have a good
idea of what JSP is. It consists of HTML or XML
markup into which special tags and code blocks
are inserted. The code is executed on the server
and the result is a dynamic page that is returned
to the client browser. Although JSPs are simple
to build they have at their disposal the full
power of object-oriented Java and the Java Server
API. JSPs make heavy use of Java Beans, which are
classes that follow a standard pattern of a
no-argument constructor (required in JSPs) and
public GET and SET methods.
27Java Beans - http//en.wikipedia.org/wiki/Java_Bea
ns
- JavaBeans are software components written in the
Java programming language. - The JavaBeans specification by Sun Microsystems
defines them as "reusable software components
that can be manipulated visually in a builder
tool". - In spite of many similarities, JavaBeans should
not be confused with Enterprise JavaBeans (EJB),
a server-side component technology that is part
of J2EE. - In order to function as a JavaBean class, an
object class must obey certain conventions about
method naming, construction, and behavior. These
conventions make it possible to have tools that
can use, reuse, replace, and connect JavaBeans. - The required conventions are
- The class should be serializable (able to
persistently save and restore its state) - It should have a no-argument constructor
- Its properties should be accessed using get and
set methods that follow a standard naming
convention - It should contain any required event-handling
methods - Because these requirements are largely expressed
as conventions rather than by implementing
interfaces, some developers view Java Beans as
Plain Old Java Objects that follow certain naming
conventions. However, this view is misleading for
Java Beans that support event handling, because
the method conventions and associated support
classes for event handling are fairly intricate,
and require the use of specific base classes and
interfaces.
28EJB - http//en.wikipedia.org/wiki/EJB
- The Enterprise JavaBeans specification is one of
the several Java APIs in the Java 2 Platform,
Enterprise Edition. EJB is a server-side
component that encapsulates the business logic of
an application. - The specification details how an application
server provides server-side objects known as
Enterprise JavaBeans, or EJBs, with - persistence
- transactions
- concurrency control
- events using Java Message Service
- naming and directory services
- security
- deployment of components in an application server
- remote communication using CORBA
- Additionally, the Enterprise JavaBean
specification defines the roles played by the EJB
container and the EJBs as well as how to deploy
the EJBs in a container.
29J2EE - http//www.webopedia.com/TERM/J/J2EE.html
- Short for Java 2 Platform Enterprise Edition.
J2EE is a platform-independent, Java-centric
environment from Sun for developing, building and
deploying Web-based enterprise applications
online. The J2EE platform consists of a set of
services, APIs, and protocols that provide the
functionality for developing multitiered,
Web-based applications. Some of the key features
and services of J2EE - At the client tier, J2EE supports pure HTML, as
well as Java applets or applications. It relies
on Java Server Pages and servlet code to create
HTML or other formatted data for the client. - Enterprise JavaBeans (EJBs) provide another layer
where the platform's logic is stored. An EJB
server provides functions such as threading,
concurrency, security and memory management.
These services are transparent to the author. - Java Database Connectivity (JDBC), which is the
Java equivalent to ODBC, is the standard
interface for Java databases. - The Java servlet API enhances consistency for
developers without requiring a graphical user
interface.
30J2EE - http//en.wikipedia.org/wiki/J2EE
- Java Platform, Enterprise Edition or Java EE
(formerly also J2EE) is a programming platform
part of the Java platform for developing and
running distributed multi-tier architecture
applications, based largely on modular components
running on an application server. The Java EE
platform is defined by a specification. Java EE
is also considered informally to be a language or
standard because providers must agree to certain
conformance requirements in order to declare
their products as Java EE compliant albeit with
no ISO or ECMA standard. - Java EE includes several API specifications, such
as JDBC, client-side applets, RPC, CORBA, and
defines how to coordinate them. Java EE also
features some specifications unique to Java EE
for components. These include Enterprise Java
Beans, servlets, portlets (following the JSR 168
specification), JavaServer Pages and several web
service technologies. This allows the developer
to create an enterprise application that is
portable between platforms and scalable, while
integrating with legacy technologies.
31Apache - http//httpd.apache.org/
- The Apache HTTP Server Project is an effort to
develop and maintain an open-source HTTP server
for modern operating systems including UNIX and
Windows NT. The goal of this project is to
provide a secure, efficient and extensible server
that provides HTTP services in sync with the
current HTTP standards. - Apache has been the most popular web server on
the Internet since April 1996. The November 2005
Netcraft Web Server Survey found that more than
70 of the web sites on the Internet are using
Apache, thus making it more widely used than all
other web servers combined. - The Apache HTTP Server is a project of the Apache
Software Foundation.
32Tomcat - http//java.sun.com/products/jsp/tomcat/
- is a free, open-source implementation of Java
Servlet and JavaServer Pages technologies
developed under the Jakarta project at the Apache
Software Foundation. - Apache Tomcat is the servlet container that is
used in the official Reference Implementation for
the Java Servlet and JavaServer Pages
technologies.
33Spring Framework - http//www.springframework.org/
about
- The most complete lightweight container,
providing centralized, automated configuration
and wiring of your application objects. The
container is non-invasive, capable of assembling
a complex system from a set of loosely-coupled
components (POJOs) in a consistent and
transparent fashion. The container brings
agility and leverage, and improves application
testability and scalability by allowing software
components to be first developed and tested in
isolation, then scaled up for deployment in any
environment (J2SE or J2EE). - A common abstraction layer for transaction
management, allowing for pluggable transaction
managers, and making it easy to demarcate
transactions without dealing with low-level
issues. Generic strategies for JTA and a single
JDBC DataSource are included. In contrast to
plain JTA or EJB CMT, Spring's transaction
support is not tied to J2EE environments. - A JDBC abstraction layer that offers a meaningful
exception hierarchy (no more pulling vendor codes
out of SQLException), simplifies error handling,
and greatly reduces the amount of code you'll
need to write. You'll never need to write another
finally block to use JDBC again. The
JDBC-oriented exceptions comply to Spring's
generic DAO exception hierarchy. - Integration with Toplink, Hibernate, JDO, and
iBATIS SQL Maps in terms of resource holders,
DAO implementation support, and transaction
strategies. First-class Hibernate support with
lots of IoC convenience features, addressing many
typical Hibernate integration issues. All of
these comply to Spring's generic transaction and
DAO exception hierarchies. - AOP functionality, fully integrated into Spring
configuration management. You can AOP-enable any
object managed by Spring, adding aspects such as
declarative transaction management. With Spring,
you can have declarative transaction management
without EJB... even without JTA, if you're using
a single database in Tomcat or another web
container without JTA support. - A flexible MVC web application framework, built
on core Spring functionality. This framework is
highly configurable via strategy interfaces, and
accommodates multiple view technologies like JSP,
Velocity, Tiles, iText, and POI. Note that a
Spring middle tier can easily be combined with a
web tier based on any other web MVC framework,
like Struts, WebWork, or Tapestry.
34Struts - http//struts.apache.org/
- The goal of the Apache Struts project is to
encourage application architectures based on the
"Model 2" approach, a variation of the classic
Model-View-Controller (MVC) design paradigm.
Under Model 2, a servlet (or equivalent) manages
business logic execution, and presentation logic
resides mainly in server pages. - The Apache Struts project encourages Model 2
designs in two ways. First, by providing open
source frameworks and toolkits that help
developers build applications for the web.
Second, by providing friendly and honest mailing
lists where both newcomers and veterans discuss
how to use Struts software in their own Model 2
applications.
35Tapestry - http//jakarta.apache.org/tapestry/inde
x.html
- Tapestry is an open-source framework for creating
dynamic, robust, highly scalable web applications
in Java. Tapestry complements and builds upon the
standard Java Servlet API, and so it works in any
servlet container or application server. - Tapestry divides a web application into a set of
pages, each constructed from components. - Developing Tapestry applications involves
creating HTML templates using plain HTML, and
combining the templates with small amounts of
Java code using (optional) XML descriptor files.
- In Tapestry, you create your application in terms
of objects, and the methods and properties of
those objects -- and specifically not in terms of
URLs and query parameters. Tapestry brings true
object oriented development to Java web
applications.
36BeeHive - http//beehive.apache.org/
- The Beehive goal is to make J2EE programming
easier by building a simple object model on J2EE
and Struts. Using the new JSR-175 annotations,
Beehive reduces the coding necessary for J2EE.
The initial Beehive project has three pieces. - NetUI An annotation-driven web application
programming framework that is built atop Struts.
NetUI centralizes navigation logic, state,
metadata, and exception handling in a single
encapsulated and reusable Page Flow Controller
class. In addition, NetUI provides a set of JSP
tags for rendering HTML / XHTML and higher-level
UI constructs such as data grids and trees and
has first-class integration with JavaServer Faces
and Struts. - Controls A lightweight, metadata-driven
component framework for building that reduces the
complexity of being a client of enterprise
resources. Controls provide a unified client
abstraction that can be implemented to access a
diverse set of enterprise resources using a
single configuration model. - Web Service Metadata (WSM) An implementation of
JSR 181 which standardizes a simplified,
annotation-driven model for building Java web
services. - In addition, Beehive includes a set of system
controls that are abstractions for low-level J2EE
resource APIs such as EJB, JMS, JDBC, and web
services.
37Hibernate - http//www.hibernate.org/
- Hibernate is a powerful, high performance
object/relational persistence and query service.
- Hibernate lets you develop persistent classes
following object-oriented idiom - including
association, inheritance, polymorphism,
composition, and collections. - Hibernate allows you to express queries in its
own portable SQL extension (HQL), as well as in
native SQL, or with an object-oriented Criteria
and Example API.
38iBatis - http//ibatis.apache.org/
- The iBATIS Data Mapper framework makes it easier
to use a database with Java and .NET
applications. iBATIS couples objects with stored
procedures or SQL statements using a XML
descriptor. - This framework maps classes to SQL statements
using a very simple XML descriptor.
39Maven - http//maven.apache.org/
- Maven is a software project management and
comprehension tool. Based on the concept of a
project object model (POM), Maven can manage a
project's build, reporting and documentation from
a central piece of information.
40End of End Notes Chapters 4 and 5
41Ruby
- Dynamic
- Fully object-oriented
- Interpreted
42OO
- Everything is an object (ints, strings, etc.)
- irb(main)0020gt 7
- gt 7
- irb(main)0030gt 7.class
- Fixnum
- irb(main)0110gt 7.5.round
- gt 8
- irb(main)0120gt nil.class
- gt NilClass
43Typing
- Dynamically typed
- irb(main)0130gt n1
- gt 1
- irb(main)0140gt n.class
- gt Fixnum
- irb(main)0150gt n"bbs"
- gt "bbs"
- irb(main)0160gt n.class
- gt String
44Typing
- Strongly typed
- irb(main)0170gt n3
- TypeError cannot convert Fixnum into String
- from (irb)17in '
- from (irb)17
45Conditionals
- irb(main)0200gt def silence?(b)
- irb(main)0211gt puts "aaaa" if b
- irb(main)0221gt end
- gt nil
- irb(main)0230gt silence? true
- aaaa
- gt nil
- irb(main)0250gt silence? false
- gt nil
- irb(main)0260gt silence? 0
- aaaa
- gt nil
- irb(main)0280gt silence? nil
- gt nil
46Looping
- irb(main)0300gt puts line while line gets
- "aaa"
- "aaa"
- one
- one
- two
- two
- three
- three
- Z
- gt nil
47Ranges
- irb(main)0310gt range 1..3
- gt 1..3
- irb(main)0320gt range.class
- gt Range
- irb(main)0330gt ('a'..'z')'h'
- gt true
- irb(main)0340gt ('a'..'z')'H'
- gt false
- irb(main)0350gt (1..10) 5
- gt true
48Ranges
- irb(main)0360gt for c in 'g'.. 'j'
- irb(main)0371gt print c '-'
- irb(main)0381gt end
- g-h-i-j-gt "g".."j"
- irb(main)0390gt for c in 'g'.. 'j'
- irb(main)0401gt puts c
- irb(main)0411gt end
- g
- h
- i
- j
- gt "g".."j"
49Regular Expressions
- irb(main)0420gt regex /better/
- gt /better/
- irb(main)0430gt regex.class
- gt Regexp
- irb(main)0440gt "Mine is bigger" regex
- gt nil
- irb(main)0450gt "Mine is better" regex
- gt 8
50Containers - Hashes
-
- irb(main)0460gt numbers0gt"zero", 1gt"one",
2gt"two", 3gt"three" - gt 0gt"zero", 1gt"one", 2gt"two", 3gt"three"
- irb(main)0470gt 4.times i puts numbersi
- zero
- one
- two
- three
- gt 4
51Containers - Arrays
- irb(main)0480gt stack 1,2,3
- gt 1, 2, 3
- irb(main)0490gt stack.push "cat"
- gt 1, 2, 3, "cat"
- irb(main)0500gt stack.pop
- gt "cat"
- irb(main)0510gt stack
- gt 1, 2, 3
52Files
- A simple GREP
- File.open(ARGV0) do file
- rx Regexp.new(ARGV1)
- while linefile.gets
- puts line if line rx
- end
- end
- ruby grep.rb filename regex
53Applying Some Structure
- Inside-out Refactoring
- Group common code in libraries
- Call them in your methods
- Outside in refactoring
- Your methods can
- take code-blocks as parameters
- call them
- even pass parameters to them
54Outside-in Refactoring
- def threeTimes
- yield
- yield
- yield
- end
- threeTimes puts "Hello"
- produces
- Hello
- Hello
- Hello
55Classes
- calculator.rb
- class Calculator
- def initialize
- _at_total 0
- end
- def add(x)
- _at_total x
- end
- def subtract(x)
- _at_total - x
- end
-
- end
56Classes
- irb(main)0010gt require calculator
- NameError undefined local variable or method
calculator' for mainObject - from (irb)1
- irb(main)0020gt require 'Calculator'
- gt true
- irb(main)0030gt c Calculator.new
- gt ltCalculator0x2bd2500 _at_total0gt
- irb(main)0040gt c.add 100
- gt 100
- irb(main)0050gt c.subtract 40
- gt 60
57Classes
- irb(main)0060gt class Calculator
- irb(main)0071gt def reset
- irb(main)0082gt _at_total 0
- irb(main)0092gt end
- irb(main)0101gt end
- gt nil
- irb(main)0110gt c.reset
- gt 0
58Classes
- irb(main)0120gt class IrsCalculator lt Calculator
- irb(main)0131gt def add(x)
- irb(main)0142gt x x/2 if xgt0
- irb(main)0152gt super
- irb(main)0162gt end
- irb(main)0171gt end
- gt nil
- irb(main)0180gt c IrsCalculator.new
- gt ltIrsCalculator0x2bba038 _at_total0gt
- irb(main)0190gt c.add 100
- gt 50
59Classes
- irb(main)0200gt Class.superclass
- gt Module
- irb(main)0210gt Module.superclass
- gt Object
- irb(main)0220gt Object.superclass
- gt nil
60Mixins
- Interfaces with implementation
- Can access the including classs methods
- Partly adds the benefit of multi-inheritance
- Implemented using Modules
61Interceptors
- You can rename methods on-the-fly
- class Class
- alias_method orig_new, new
- def new(args)
- result orig_new(args)
- print Unattended laptop error!
- puts result
- return result
- end
- end
62Interceptors
- irb(main)0010gt require "Class"
- gt true
- irb(main)0020gt a1,2,3
- ltRubyTokenTkIDENTIFIER0x2941d40gt
- ltRubyTokenTkASSIGN0x2941b48gt
- ltRubyTokenTkLBRACK0x2941950gt
- ltRubyTokenTkINTEGER0x29416c8gt
- ltRubyTokenTkCOMMA0x29414d0gt
- ltRubyTokenTkINTEGER0x2941278gt
- ltRubyTokenTkCOMMA0x29410b0gt
- ltRubyTokenTkINTEGER0x2940e70gt
- ltRubyTokenTkRBRACK0x2940c60gt
- ltRubyTokenTkNL0x2940438gt
- gt 1, 2, 3
63Ruby On Rails
- What is it?
- Rails is a full-stack, open-source webframework
in Ruby for writing real-worldapplications with
joy and less code thanmost frameworks spend
doing XML sit-upsDavid H. Hansson
64Some Numbers
- The authors test case gives shows impressively
superior numbers for Rails over
Java/Spring/Hibernate solution in development
time/code size as well as performance in most
cases.
65Architecture
66Under the Hood
- Active RecordIts a wrapper around a db table,
with domain logic built into the wrapper. You can
also do inheritance and manage relationships. - Action PackSplits the request into a controller
part and a view part.
67Showcases
- RubyBB by Russ Smith
- http//rubybb.readbim.com/
- 384 Lines of Code
- StoryCards Web app to support XP style dev. by
Jim Weirich - http//onestepback.org3030/
- 1,250 Lines of code 8 hours of development time
- Basecamp A commercial Rails web-app with over
10,000 users. - Web-based project management
- http//www.basecamphq.com/
- Launched after 4,000 Lines of Code.
- 2 man-months of months of programming by a single
developer
68End of Presentation