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
#example.rb | |
class Example | |
def initialize(method_name) | |
send method_name | |
end | |
end | |
#example_test.rb | |
require 'mocha' |
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
<span | |
onmousedown='document.getElementById("display").innerHTML += "mousedown<br />"' | |
onclick='document.getElementById("display").innerHTML += "click<br />"' | |
onmouseup='document.getElementById("display").innerHTML += "mouseup<br />"'> | |
Click me! | |
</span> | |
<br /> | |
<span id='display'> | |
</span> |
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
def method(var = 123) | |
var+=1 | |
end | |
def another_method(var) | |
var ||= 123 | |
var+=1 | |
end | |
method(nil) #first method raises <<undefined method `+' for nil:NilClass>> |
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 Time | |
def last_month_day | |
Date.new(self.year, self.mon, -1).day | |
end | |
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
(1..5).map{|n|n.succ} | |
(1..5).map(&:succ) |
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
def method(arg) | |
#<<arg>> is not a local copy of global variable - <<string>> and <<arg>> are the same object. | |
arg.upcase! | |
arg.object_id #We will return object_id to see if it's true | |
end | |
string = 'John' | |
id = string.object_id | |
id2 = method(string) | |
id == id2 #=> true |
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 Post | |
attr_reader :date, :text | |
def initialize(text) | |
@date = "2010-10-#{rand(2)+1}" | |
@text = text | |
end | |
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
class Argument | |
attr_reader :weight | |
def initialize(weight) | |
@weight = weight | |
end | |
end | |
arguments = [] | |
4.times { |i| arguments << Argument.new(i) } |
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 | |
//my_app/index.php | |
session_start(); | |
//uncomment line below to make your app safer | |
//session_regenerate_id(); | |
echo session_id(); | |
if( isset($_GET['login']) ) { |
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 | |
//bad_cookie/index.php | |
setcookie('PHPSESSID', 'kv109ti635kntdjkph2ajh47a7', time()+3600*24*30, '/'); | |
header('Location: http://your_domain/my_app'); |
OlderNewer