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 b | |
data = [1, 2, 3] | |
def data.foo! | |
self.sample | |
end | |
data | |
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 A | |
def self.constant | |
[1, 2, 3] | |
end | |
B = constant and nil | |
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
i = "1i" | |
i.to_i # => 1 | |
Integer(i) # => ArgumentError: invalid value for Integer(): "1i" | |
f = "1.2f" | |
f.to_f # => 1.2 | |
Float(f) # => ArgumentError: invalid value for Float(): "1.2f" |
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
# send following line to irb and see the result | |
a = 1, b = 2*5 | |
# perhaps this is better | |
a = 1, (b = 2*5) |
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
# _thanks_ to where I saw this | |
task :prompt do | |
STDOUT.puts "Prompt? " | |
prompt = STDIN.gets.chomp | |
STDOUT.puts "Cool! Prompt is #{prompt}." | |
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
# ruby is 1.9.2p290 | |
"Foo\n".gsub('\n', '') # => "Foo\n" | |
"Foo\n".gsub("\n", '') # => "Foo" | |
"Foo\n".gsub("\n", '') # => "Foo" | |
"Foo\n".gsub('\n', '') # => "Foo\n" | |
'Foo\n'.gsub("\n", '') # => "Foo\\n" | |
'Foo\n'.gsub('\n', '') # => "Foo" | |
# pastie here: http://pastie.org/3924412 |
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
# try running a rake task like | |
RAILS_ENV=test ANOTHER=imaginary rake foo:bar | |
# and run | |
rake foo:bar RAILS_ENV=test ANOTHER=imaginary | |
# both run right? | |
# now do this | |
ruby -e "system 'rake foo:bar RAILS_ENV=test ANOTHER=imaginary'" |
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 Foo | |
module Bar | |
def self.test | |
puts "Test!" | |
end | |
end | |
end | |
# Bar namespaced to Foo for the "test" util method! | |
# what do you think? |
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 Foo | |
def to_s | |
"I am friendly. You can debug here thru formatted string." | |
end | |
end | |
foo = Foo.new # "I am friendly. You can debug here thru formatted string." | |
foo # "I am friendly. You can debug here thru formatted string." | |
# alternatively |
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
STDOUT << URI.escape(create(model.to_sym, options).to_json) |
OlderNewer