This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A { | |
public static $name = null; | |
} | |
A::$name = "a"; | |
class B extends A { | |
} | |
B::$name = "b"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pessoa | |
include Comparable | |
attr_accessor :nome | |
def initialize(nome) | |
self.nome = nome | |
end | |
def <=>(outra) | |
return -1 if outra.size<self.nome.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pessoa | |
attr_accessor :nome | |
def initialize(nome) | |
self.nome = nome | |
end | |
def ==(outra) | |
outra == self.nome | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if ! which md5sum > /dev/null; then | |
echo Install md5sum | |
exit 1 | |
fi | |
if ! which curl > /dev/null; then | |
echo Install curl | |
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
include Benchmark | |
values = (0..1000).to_a | |
bm(10) do |bench| | |
bench.report("regular") do | |
values.map { |x| x * 10 }.select { |x| x > 30 } | |
end | |
bench.report("lazy") do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
include Benchmark | |
values = (0..100).to_a | |
bm(10) do |bench| | |
bench.report("regular") do | |
values.map { |x| x * 10 }.select { |x| x > 30 } | |
end | |
bench.report("lazy") do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
natural_numbers = Enumerator.new do |yielder| | |
number = 1 | |
loop do | |
yielder.yield number | |
number += 1 | |
end | |
end | |
p natural_numbers.lazy.select { |n| n.odd? }.take(5).to_a # => [1, 3, 5, 7, 9] | |
p natural_numbers.lazy.map { |n| n*2 }.take(5).to_a # => [2, 4, 6, 8, 10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
natural_numbers = Enumerator.new do |yielder| | |
number = 1 | |
loop do | |
yielder.yield number | |
number += 1 | |
end | |
end | |
p natural_numbers.select { |n| n.odd? }.take(5).to_a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
regexp = /^([A-Z])?[a-z]+(?(1)[A-Z]|[a-z])$/ | |
p regexp =~ "foo" #=> 0 | |
p regexp =~ "foO" #=> nil | |
p regexp =~ "FoO" #=> 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TimeExtensions | |
refine Fixnum do | |
def minutes; self * 60; end | |
end | |
end | |
class MyApp | |
using TimeExtensions | |
def initialize | |
p 2.minutes |