2. RubyGems || Pear && Pecl
• Konsistentere Paketverwaltung RubyGems Pear Pecl
in Ruby
30000
• Fast jeder Anwendungsfall
existiert als fertiges Gem 22500
• „gem install rails“
15000
• Bundler && „bundle install“ 20,476
7500
654 0
258
Total
3. Syntax
• Leicht für Menschen zu lesen Ruby PHP
• Optional puts "Hello World" <?php
echo "Hello Worldn";
?>
• Keine <?php ?>s
• Keine ;s
• Keine ns
• Optionale ()s
4. Objektorientierung
• Alles ist ein Objekt Ruby
• Zahlen, Strings, alles... 3.times do
puts "Hello " +
"daniel".capitalize
end
• Objektorientierung von der ersten Sekunde # Prints:
# Hello Daniel
# Hello Daniel
# Hello Daniel
5. Objektorientierte Syntax
• obj.attribute = method Ruby PHP
• dangerous! und query? full = "daniel Spangenberg"
names = full.split
<?php
$full = "daniel spangenberg";
methoden until names.empty?
$names = explode(" ", $full);
names.first.capitalize! if (size($names) > 0) {
puts names.shift $names[0] = ucwords($names[0]);
end echo array_shift($names) . "n";
}
# Prints:
# Daniel # Prints:
# Spangenberg # Daniel
# Spangenberg
?>
6. Klassen und viel mehr...
• Einfache Zugriffsmethoden Ruby PHP
• Überschreiben der class Greeter
attr_accessor :who
<?php
class Greeter {
Ruby Methoden function getWho() {
$this->who;
def initialize(greetring)
}
@greetring = greeting
@who = "World"
function setWho($who) {
end
$this->who = $who;
}
def to_s
"#{@greetring} #{@who}!"
function __construct($greeting) {
end
$this->greeting = $greeting;
end
$this->who = "World";
}
hello = Greeter.new("Hello")
hello.who = "Daiel"
function __toString() {
puts hello
return $this->greeting . " " .
$this->who;
# Prints:
}
# Hello Daniel
}
$hello = new Greeter("Hello");
$hello->setWho("Daniel");
echo $hello . "n";
?>
7. Blocks und „Core Type Monkey Patches“
Ruby
describe MyClass do
it "adds two and two" do
sum = MyClass.add(2, 2)
sum.should == 4
end
end
describe MyClass do
it "adds two and two" do
sum = MyClass.add(2, 2)
sum.should == 4
end
end