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 Fixnum | |
def amicable? | |
b = self.divisors.sum | |
return b != self && b.divisors.sum == self | |
end | |
def divisors | |
(1..self/2).select{|x| self % x == 0} | |
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
def add_n(n) | |
Proc.new {|x| x + n } | |
end | |
add_5 = add_n(5) | |
add_5.call(1) | |
add_5.call(7) | |
add_10 = add_n(10) | |
add_10.call(add_5.call(4)) |
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 Sudoku | |
def initialize | |
@puzzle = Array.new(9) {Array.new(9, 0)} | |
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 Date | |
def wday_name | |
self.strftime("A") | |
end | |
end | |
Date.yesterday.wday_name #=> "Tuesday" |
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 MyProxy < BasicObject | |
def initialize(target) | |
@target = target | |
end | |
def method_missing(name, *args, &block) | |
@target.send(name, *args, &block) | |
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) Delicious::BookmarkList should find the bookmark title, address and description of the bookmark list provided | |
Failure/Error: bookmark_list.bookmarks.should == [{:title => "Access to MySQL", :link => "http://www.bullzip.com/products/a2m/info.php", :description => "Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}] | |
expected: [{:title=>"Access to MySQL", :link=>"http://www.bullzip.com/products/a2m/info.php", :description=>"Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}], | |
got: [{:title=>"Access To MySQL", :link=>"http://www.bullzip.com/products/a2m/info.php", :description=>"Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}] (using ==) | |
# ./spec/models/delicious/bookmark_list_spec.rb:7:in `block (2 levels) in <top (required)>' |
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 Foobar | |
@city = "London" | |
def city | |
self.class.instance_variable_get(:@city) | |
end | |
end | |
class Barfoo < Foobar | |
@city = "New York" |
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 Foobar | |
attr_accessor :locale | |
def initialize(locale = 'sv') | |
@locale = locale | |
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
<?php | |
include_once MODEL_PATH.'forums/Forum.php'; | |
include_once MODEL_PATH.'forums/Topic.php'; | |
require_once MODEL_PATH.'socialNetwork/group/XACLGroup.php'; | |
/** | |
* InitTopic | |
* | |
* This controller | |
* |
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
<% if local_assigns.include?(:phone) && local_assigns.include?(:location) %> | |
<ul class="profile_info_triple"> | |
<li><%= link_to(fb_name(owner, :use_you => false, :linked => false), owner) %></li> | |
<li><%= location %></li> | |
<li class="phone"><%= phone %></li> | |
</ul> | |
<% elsif local_assigns.include?(:phone) || local_assigns.include?(:location) %> | |
<ul class="profile_info_dual"> | |
<li><%= link_to(fb_name(owner, :use_you => false, :linked => false), owner) %></li> | |
<li class="phone"><%= phone %></li> |