Skip to content

Instantly share code, notes, and snippets.

View jacegu's full-sized avatar
🦖
Juggling shipping and parenting

Javier Acero jacegu

🦖
Juggling shipping and parenting
View GitHub Profile
@jacegu
jacegu / .vimrc
Created March 9, 2011 20:06
Disable arrows in Vim
"Disable arrows
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
@jacegu
jacegu / even_more_access_control_examples.rb
Created February 13, 2011 20:01
An example of declaring visibility of existing methods in Ruby.
class EvenMoreAccessControlExamples
def public_by_default
end
def protected_method
end
def this_is_public_too
end
@jacegu
jacegu / more_access_control_examples.rb
Created February 13, 2011 19:58
More examples about access control in Ruby. This one wont work.
class MoreAccessControlExamples
def public_by_default
end
protected def protected_method
end
public def this_is_public_too
end
@jacegu
jacegu / access_control_examples.rb
Created February 13, 2011 19:55
A little example for access control declaration in Ruby
class AccessControlExamples
def public_method_by_default
end
protected
def first_protected_method
end
def second_protected_method
end
@jacegu
jacegu / mixins2.rb
Created January 22, 2011 20:58
A little example of mixing in Comparable module
class ComputerBrand
include Comparable
attr_reader :name
def initialize(name)
@name = name
end
def <=>(other)
@jacegu
jacegu / mixins1.rb
Created January 22, 2011 20:17
A little example to illustrate how mixins work in Ruby
module ModuleExample
def self.hello_world
puts 'This is a static hello world from a module'
end
def hello_world
puts 'This is a non static hello world from a module'
end
end
@jacegu
jacegu / modules1.rb
Created January 18, 2011 18:13
A little example about modules and namespaces
module AModule
class String
def i_like_open_classes
puts "#{self} hasn't been monkey patched"
end
end
end
string = String.new
begin
@jacegu
jacegu / namespace.rb
Created January 18, 2011 18:09
An example to show the use of :: the namespace resolving operator in ruby.
class MyClass
CONSTANT = 'hello world'
end
puts MyClass::CONSTANT
begin
puts MyClass.CONSTANT
rescue NoMethodError
puts 'With dot notation we are sending a message to class MyClass'
@jacegu
jacegu / modules2.rb
Created January 18, 2011 18:06
Another example of ruby modules, this time to illustrate static and non static methods inside a module.
module ModuleExample
def self.hello_world
puts 'This is a static hello world from a module'
end
def hello_world
puts 'This is a non static hello world from a module'
end
end
@jacegu
jacegu / greed_dice_game.rb
Created January 4, 2011 18:47
My implementation of greed dice game for Ruby Koans
class Roll
FIFTY_POINTS = 50
HUNDRED_POINTS = 100
THOUSAND_POINTS = 1000
def initialize(rolls)
@ocurrences = ocurrences_of_each_number(rolls)
end
def score