This file contains hidden or 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 'socks/templates' | |
module Myapp | |
class App | |
include Socks::Templates | |
Router = HttpRouter.new do | |
# ... | |
end | |
end | |
end |
This file contains hidden or 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
RSpec::configure do | |
def some_helper | |
puts "Do something that helps RSpec here." | |
end | |
end |
This file contains hidden or 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
load ('Somefile') || ('somefile') # Load a custom file |
This file contains hidden or 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 Town | |
def initialize(&block) | |
@attr = some_attr | |
instance_eval &block | |
end | |
def restaurant(name, &block) | |
@nested_attr = "define attributes affecting restaurant here." | |
instance_eval &block | |
end |
This file contains hidden or 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
puts "This is %{a_string}" %{ :a_string => 'a string.' } |
This file contains hidden or 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
Object.defineProperty String, 'capitalize', value: -> | |
this[0].toUpperCase() + this[1...] | |
console.log char for char of 'str' | |
# => 0, 1, 2 |
This file contains hidden or 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 Socks | |
module VERSION | |
MAJOR = '0' | |
MILD = '2' | |
MINOR = '10' | |
PRE = 'beta' | |
FULL = [MAJOR, MILD, MINOR, PRE].compact.join('.') # 0.2.10.beta | |
end | |
end |
This file contains hidden or 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
system("echo 'Foo!'") | |
#=> Foo! | |
require 'rake' | |
sh("echo 'Foo!'") | |
#=> | |
# echo "Foo!" # It prints the commnd it's about to do! | |
# Foo! # Then runs it. |
This file contains hidden or 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
# It's good to remove any nil values, thus cleaning up an array when in use. | |
[1, 2, nil 3, nil].compact | |
#=> [1, 2, 3] |
This file contains hidden or 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
# Rake's sh() can have a negative effect by printing the given | |
# command before running it. (see https://gist.github.com/2669372) | |
# This can look pretty ugly. Luckily, using system(), you can write tyour own method to avoid this. | |
def sh(code) | |
system(code) # Simple. | |
end |