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 Array | |
def randomize | |
self.sort {rand(self.length / 2)-1} | |
end | |
def randomize! | |
self.sort! {rand(self.length / 2)-1} | |
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
# File: person_module.rb | |
module Person | |
def age | |
Time.now - self.birthday | |
end | |
end | |
# File: main.rb | |
require 'person_module' |
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 Queue | |
@@list = [] | |
def self.add(entry) | |
@@list << entry | |
end | |
def self.list | |
@@list | |
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 String | |
def camelize(first_letter_in_uppercase = :upper) | |
s = gsub(/\/(.?)/){|x| "::#{x[-1..-1].upcase unless x == '/'}"}.gsub(/(^|_)(.)/){|x| x[-1..-1].upcase} | |
s[0...1] = s[0...1].downcase unless first_letter_in_uppercase == :upper | |
s | |
end | |
def constantize | |
raise(NameError, "#{inspect} is not a valid constant name!") unless m = /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/.match(self) | |
Object.module_eval("::#{m[1]}", __FILE__, __LINE__) |
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 AppleTree | |
def initialize | |
puts "OMG! /root" | |
end | |
end | |
module NS | |
class AppleTree | |
def initialize | |
puts "ROFL /root/NS" |
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
diff --git a/pivotal_tracker.rb b/pivotal_tracker.rb | |
index 8ed3884..03da167 100644 | |
--- a/pivotal_tracker.rb | |
+++ b/pivotal_tracker.rb | |
@@ -170,7 +170,7 @@ private | |
:estimate => doc.at('estimate').innerHTML, | |
:current_state => doc.at('current_state').innerHTML, | |
:description => doc.at('description').innerHTML, | |
- :url => doc.at('url').innerHTML | |
+ :url => doc.at('url').innerHTML, |
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 gen_log_base(base) | |
return Proc.new { |num| Math.log(num, base) } | |
end | |
log2 = gen_log_base(2) | |
log10 = gen_log_base(10) | |
puts log2.call(4) | |
puts log10.call(100) |
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
# Title | |
feelings = {:happy => 1, :suicide => 0} | |
supernaturals = { } | |
begin | |
# begining | |
me = i = Person.new | |
you = Angel.new | |
i.love you if you.love? me |
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 TestCucc | |
include MongoMapper::Document | |
key :cucc, Integer | |
validates_true_for :cucc, | |
:logic => lambda { | x | x.cucc >= 1 && x.cucc <= 5 }, | |
:message => "must be in the following range: 1 to 5" | |
end | |
=begin | |
ruby-1.9.2-p0 > load "t.rb" |
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 A | |
def test | |
puts "A::test" | |
end | |
end | |
class B | |
def test | |
puts "B::test" | |
C.a.test |
OlderNewer