SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Ruby

Mostafa Menessy & Hesham shabana
Outline
- Ruby Building Blocks
Bot Network
- Code Samples
Ruby On Rails
PE Packer
- Advantages/Disadvantages Of Ruby
- Ruby Internals ( if there is enough time )
Ruby Building Blocks - Data types
- Built-in data types aren’t declared
x=5 ; y = “10” ; z = [] , f = { "a" => 100, :b => 5 }
x = Array.new ; x = [] ; x << "Word" ; puts x.pop ; puts x.length

- Data types can dynamically change during
runtime execution.
- Constants are defined by Capitalizing the first
letter
Ruby Building Blocks - Control Flow
CONDITIONS :
:
if tall < 150
puts "You can’t be a pilot"
elsif tall > 220
puts "You’re unique"
end
puts "You're a teenager" if age > 12 && age <
20
puts"You're NOT a teenager" unless age > 12
&& age < 20
x=20,y=12
puts "You're NOT a teenager" if x <=> y == 1

EXCEPTION:
if y == 0
raise ZeroDivisionError
else
x=x/y
end
begin
... code here ...
rescue ZeroDivisionError
... code to rescue the zero division exception here ...
rescue YourOwnException
... code to rescue a different type of exception here ...
rescue
... code that rescues all other types of exception here …
retry
end
Ruby Building Blocks-LOOPS/BLOCKS
5.times do ...code to loop here... end
5.times { ...code to loop here... }
1.upto(5) { ...code to loop here... }
10.downto(5) { ...code to loop here... }
0.step(50, 5) { ...code to loop here... }
"xyz".scan(/./) { |letter| puts letter if letter == ‘x’ else redo }
"xyz".scan(/./) { |letter| puts letter if letter == ‘x’ else retry }
[1, "test", 2, 3, 4].each { |element| puts element.to_s }
i=1
i = i * 2 until i > 1000
while (i < a.length)
puts a[i].to_s + "X"
i += 1
end
for i in 5..9
puts i
end

for i in 5...9
puts i
end

class Array
def reverse_iterate
if block_given?
current_index = self.size-1
while current_index >= 0
yield self[current_index]
current_index -= 1
end
else
print self.reverse
end
end
end
[2,4,6,8].reverse_iterate
8642
[2,4,6,8].reverse_iterate { |x| puts x }
8
6
4
2
Ruby Building Blocks -

OOP

- All of the constructs of the language are
treated as objects. Checking the data types is
done through *.class
$global_var = “”
class the_class

class Document
attr_accessor: magic_word

attr_accessor :length
attr_reader : getter_only

def name
@name
end
def name=(name)
@name = name
end

end
example = the_class.new

def initialize w, h
@width, @height = w, h
end
def [](index)
words[index]
end
def ==(other)
return magic_word == other.magic_word
end
end

class Example < SuperExample
@@counter = 0
@instance_counter = 0
def initialize
@@counter += 1
@instance_counter = @@counter
super
end
end
Packets through a Bot

Primitive C&C Network
Cont’d -- Payload
Who hates Vodafone ?
What is Rails
- Open source web application framework
written in Ruby language
- Built using the MVC pattern
Rails Application
- Convention over configuration
- DRY
- save time
- reuse code
- maintain

rails [app_name] -d mysql
Folder structure
app/

Contains the controllers, models, views, helpers, mailers and assets for your application.

app/controller

The controllers subdirectory.

app/view

The models subdirectory.

app/model

The views subdirectory.

config/

Configure your application's runtime rules, routes, database, and more.

db/

Contains your current database schema, as well as the database migrations.

public/

The only folder seen to the world as-is. Contains the static files and compiled assets.

assest/

Contains the images, style sheets, javascript.

test/

Unit tests, fixtures, and other test apparatus.

mailers/

Contains the email, templates.
The MVC pattern
The Model View Controller principle divides the
work of an application into three separate but
closely cooperative subsystems.
The MVC pattern
MVC - Model
Rails Active Record
- Rails Active Record is the Object/Relational Mapping
(ORM) layer: tables map to classes,rows map to objects
and columns map to object attributes
- Each Active Record object has CRUD (Create, Read,
Update, and Delete) methods for database access.
MVC - Model: Implementation
rails generate model book
Associations: (one-to-one, one-to-many)
class Book < ActiveRecord::Base
belongs_to :subject
end
class Subject < ActiveRecord::Base
has_many :books
end
MVC - Controller
- Separates business
logic from the presentation.
- rails generate controller book

class BookController <
ApplicationController
def list
end
def show
end
def new
end
def create
end
def edit
end
def update
end
def delete
end
end
MVC - Controller: Implementation
Implementing the list Method:
def list
@books = Book.find(:all)
end

Implementing the show Method:
def show
@book = Book.find(params[:id])
end

Implementing the create Method:
def create
@book = Book.new(params[:book])
if @book.save
redirect_to :action => 'list'
else
render :action => 'new'
end
end
MVC - View
- A Rails View shares data
with controllers through
accessible variables.

<% … %>

Execute a ruby code

<%=…%>

Execute and output the result

Create Action:
<h1>Add new book</h1>
<%= start_form_tag :action => 'create' %>
<p><label for="book_title">Title</label>:
<%= text_field 'book', 'title' %></p>
<p><label for="book_price">Price</label>:
<%= text_field 'book', 'price' %></p>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to 'Back', {:action => 'list'} %>
Submit Action:
<form action="/book/create" method="post">
Back Action:
<form action="/book/list" method="post">
Routes
Route:
match ':controller(/:action(/:id))(.:format)'
http://mysite/user/get/5
http://mysite/article/ruby-on-rails.html

Custome:
get 'signup', to: 'users#new', as: 'signup'
http://mysite/signup
All together
Portable executable Encryption
Primitive PE Protector

- Encrypt the .text section data
- Append a new stub section for decrypting the
data during runtime
- Adjust the PE Header ( AddressOfEntryPoint )

Ruby PE PACKER
[(Disa)|A]dvantages Of Ruby
- Senior Ruby on Rails engineer: One of the top 5 jobs in Silicon Valley
- Perfectly suits the startup environment
- Good Contribution by the community: over 4k rubygems, and a wide
range of built -in modules
- For learning how to implement a new language
Cont’d
- Original MRI is relatively slow
- Errors don’t help so much in fixing problems

Different Implementations: Does it sound good
or bad ?
Ruby Internals ( Extra )
Is it really an interpreter ? 1.8 <= Ruby version

- Its own custom tokenization code
- LALR Bison parser generator
Involved , Parse.y and Parse.c in the
ruby source folders

YARV is Another Ruby VM
Cont’d

Extract from Ruby Under A microscope
Questions

?

Contenu connexe

Tendances

Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
Avanitrambadiya
 

Tendances (20)

Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Elm kyivfprog 2015
Elm kyivfprog 2015Elm kyivfprog 2015
Elm kyivfprog 2015
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
AngularJS Version 1.3
AngularJS  Version 1.3AngularJS  Version 1.3
AngularJS Version 1.3
 
Ruby
RubyRuby
Ruby
 
Don't panic in Fortaleza - ScalaFX
Don't panic in Fortaleza - ScalaFXDon't panic in Fortaleza - ScalaFX
Don't panic in Fortaleza - ScalaFX
 
Php Intermediate
Php IntermediatePhp Intermediate
Php Intermediate
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
 
Php converted pdf
Php converted pdfPhp converted pdf
Php converted pdf
 
Ppt php
Ppt phpPpt php
Ppt php
 
JRuby e DSL
JRuby e DSLJRuby e DSL
JRuby e DSL
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
 
Rails and Legacy Databases - RailsConf 2009
Rails and Legacy Databases - RailsConf 2009Rails and Legacy Databases - RailsConf 2009
Rails and Legacy Databases - RailsConf 2009
 
php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Ruby de Rails
Ruby de RailsRuby de Rails
Ruby de Rails
 
Php summary
Php summaryPhp summary
Php summary
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
 

Similaire à Ruby On Rails

A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
旻琦 潘
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Anton Shemerey
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
ppparthpatel123
 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Raimonds Simanovskis
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Nick Sieger
 
PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10
Adam Trachtenberg
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
outcast96
 

Similaire à Ruby On Rails (20)

Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Ruby on Rails For .Net Programmers
Ruby on Rails For .Net ProgrammersRuby on Rails For .Net Programmers
Ruby on Rails For .Net Programmers
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Ruby on Rails 中級者を目指して - 大場寧子
Ruby on Rails 中級者を目指して - 大場寧子Ruby on Rails 中級者を目指して - 大場寧子
Ruby on Rails 中級者を目指して - 大場寧子
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record
 
PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10PHP 5 + MySQL 5 = A Perfect 10
PHP 5 + MySQL 5 = A Perfect 10
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Ruby On Rails

  • 1. Ruby Mostafa Menessy & Hesham shabana
  • 2. Outline - Ruby Building Blocks Bot Network - Code Samples Ruby On Rails PE Packer - Advantages/Disadvantages Of Ruby - Ruby Internals ( if there is enough time )
  • 3. Ruby Building Blocks - Data types - Built-in data types aren’t declared x=5 ; y = “10” ; z = [] , f = { "a" => 100, :b => 5 } x = Array.new ; x = [] ; x << "Word" ; puts x.pop ; puts x.length - Data types can dynamically change during runtime execution. - Constants are defined by Capitalizing the first letter
  • 4. Ruby Building Blocks - Control Flow CONDITIONS : : if tall < 150 puts "You can’t be a pilot" elsif tall > 220 puts "You’re unique" end puts "You're a teenager" if age > 12 && age < 20 puts"You're NOT a teenager" unless age > 12 && age < 20 x=20,y=12 puts "You're NOT a teenager" if x <=> y == 1 EXCEPTION: if y == 0 raise ZeroDivisionError else x=x/y end begin ... code here ... rescue ZeroDivisionError ... code to rescue the zero division exception here ... rescue YourOwnException ... code to rescue a different type of exception here ... rescue ... code that rescues all other types of exception here … retry end
  • 5. Ruby Building Blocks-LOOPS/BLOCKS 5.times do ...code to loop here... end 5.times { ...code to loop here... } 1.upto(5) { ...code to loop here... } 10.downto(5) { ...code to loop here... } 0.step(50, 5) { ...code to loop here... } "xyz".scan(/./) { |letter| puts letter if letter == ‘x’ else redo } "xyz".scan(/./) { |letter| puts letter if letter == ‘x’ else retry } [1, "test", 2, 3, 4].each { |element| puts element.to_s } i=1 i = i * 2 until i > 1000 while (i < a.length) puts a[i].to_s + "X" i += 1 end for i in 5..9 puts i end for i in 5...9 puts i end class Array def reverse_iterate if block_given? current_index = self.size-1 while current_index >= 0 yield self[current_index] current_index -= 1 end else print self.reverse end end end [2,4,6,8].reverse_iterate 8642 [2,4,6,8].reverse_iterate { |x| puts x } 8 6 4 2
  • 6. Ruby Building Blocks - OOP - All of the constructs of the language are treated as objects. Checking the data types is done through *.class $global_var = “” class the_class class Document attr_accessor: magic_word attr_accessor :length attr_reader : getter_only def name @name end def name=(name) @name = name end end example = the_class.new def initialize w, h @width, @height = w, h end def [](index) words[index] end def ==(other) return magic_word == other.magic_word end end class Example < SuperExample @@counter = 0 @instance_counter = 0 def initialize @@counter += 1 @instance_counter = @@counter super end end
  • 7. Packets through a Bot Primitive C&C Network
  • 8. Cont’d -- Payload Who hates Vodafone ?
  • 9. What is Rails - Open source web application framework written in Ruby language - Built using the MVC pattern
  • 10. Rails Application - Convention over configuration - DRY - save time - reuse code - maintain rails [app_name] -d mysql
  • 11. Folder structure app/ Contains the controllers, models, views, helpers, mailers and assets for your application. app/controller The controllers subdirectory. app/view The models subdirectory. app/model The views subdirectory. config/ Configure your application's runtime rules, routes, database, and more. db/ Contains your current database schema, as well as the database migrations. public/ The only folder seen to the world as-is. Contains the static files and compiled assets. assest/ Contains the images, style sheets, javascript. test/ Unit tests, fixtures, and other test apparatus. mailers/ Contains the email, templates.
  • 12. The MVC pattern The Model View Controller principle divides the work of an application into three separate but closely cooperative subsystems.
  • 14. MVC - Model Rails Active Record - Rails Active Record is the Object/Relational Mapping (ORM) layer: tables map to classes,rows map to objects and columns map to object attributes - Each Active Record object has CRUD (Create, Read, Update, and Delete) methods for database access.
  • 15. MVC - Model: Implementation rails generate model book Associations: (one-to-one, one-to-many) class Book < ActiveRecord::Base belongs_to :subject end class Subject < ActiveRecord::Base has_many :books end
  • 16. MVC - Controller - Separates business logic from the presentation. - rails generate controller book class BookController < ApplicationController def list end def show end def new end def create end def edit end def update end def delete end end
  • 17. MVC - Controller: Implementation Implementing the list Method: def list @books = Book.find(:all) end Implementing the show Method: def show @book = Book.find(params[:id]) end Implementing the create Method: def create @book = Book.new(params[:book]) if @book.save redirect_to :action => 'list' else render :action => 'new' end end
  • 18. MVC - View - A Rails View shares data with controllers through accessible variables. <% … %> Execute a ruby code <%=…%> Execute and output the result Create Action: <h1>Add new book</h1> <%= start_form_tag :action => 'create' %> <p><label for="book_title">Title</label>: <%= text_field 'book', 'title' %></p> <p><label for="book_price">Price</label>: <%= text_field 'book', 'price' %></p> <%= submit_tag "Create" %> <%= end_form_tag %> <%= link_to 'Back', {:action => 'list'} %> Submit Action: <form action="/book/create" method="post"> Back Action: <form action="/book/list" method="post">
  • 21. Portable executable Encryption Primitive PE Protector - Encrypt the .text section data - Append a new stub section for decrypting the data during runtime - Adjust the PE Header ( AddressOfEntryPoint ) Ruby PE PACKER
  • 22. [(Disa)|A]dvantages Of Ruby - Senior Ruby on Rails engineer: One of the top 5 jobs in Silicon Valley - Perfectly suits the startup environment - Good Contribution by the community: over 4k rubygems, and a wide range of built -in modules - For learning how to implement a new language
  • 23. Cont’d - Original MRI is relatively slow - Errors don’t help so much in fixing problems Different Implementations: Does it sound good or bad ?
  • 24. Ruby Internals ( Extra ) Is it really an interpreter ? 1.8 <= Ruby version - Its own custom tokenization code - LALR Bison parser generator Involved , Parse.y and Parse.c in the ruby source folders YARV is Another Ruby VM
  • 25. Cont’d Extract from Ruby Under A microscope