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
<p> | |
<%= "Husband: #{husband}" %> | |
<%= "Wife: #{ begin; husband.wife; rescue NoMethodError; end}" %> | |
<%= "Status: #{ begin; husband.wife.status; rescue NoMethodError; end}" %> | |
</p> |
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
module StringAppleization | |
refine String do | |
def appleize | |
split(' ').map do |word| | |
appleize_word(word) | |
end.join(' ') | |
end | |
private |
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
module Refinements::StringNumericalConversions | |
refine String do | |
def to_integer | |
banana | |
Integer(self) | |
rescue ArgumentError | |
nil | |
end | |
private |
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] pry(main)> using Refinements::StringNumericalConversions | |
=> main | |
[2] pry(main)> "12".to_integer | |
NoMethodError: undefined method `to_integer' for "12":String | |
from (pry):2:in `<main>' | |
[3] pry(main)> class Foo | |
[3] pry(main)* using Refinements::StringNumericalConversions | |
[3] pry(main)* def bar | |
[3] pry(main)* "12".to_integer | |
[3] pry(main)* 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 Wrapper | |
attr_reader :string | |
def initialize(string) | |
@string = string | |
end | |
def upcase! | |
string.upcase! | |
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
describe "carrots diced with celery julienned" do | |
let(:chosen_carrots) { carrots_diced } | |
let(:chosen_celery) { celery_diced } | |
describe "user is selecting carrots" do | |
let(:changed_vegetable) { chosen_carrots } | |
it_sets :celery, to: :diced | |
it_does_not_change :carrots | |
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
~/personal$ mkdir git_test | |
~/personal$ cd git_test/ | |
~/personal/git_test$ git init | |
Initialized empty Git repository in /Users/baldur/personal/git_test/.git/ | |
~/personal/git_test$ echo "hi i'm a commit" > first.txt | |
~/personal/git_test$ git add first.txt | |
~/personal/git_test$ gcom -m "This is my first commit" | |
[master (root-commit) 129986c] This is my first commit | |
1 file changed, 1 insertion(+) | |
create mode 100644 first.txt |
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
poop_name_is_long = this_is_a_boolean_checker ? | |
the_stuff_you_do_for_true : | |
the_stuff_you_do_for_false | |
poop_name_is_long = | |
if this_is_a_boolean_checker | |
the_stuff_you_do_for_true | |
else | |
the_stuff_you_do_for_false | |
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 RedisModel::Base | |
attr_reader :source, :target | |
def initialize(source:, target:) | |
@source = source | |
@target = target | |
end | |
class << self | |
def all |
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 does_begin_matter? | |
puts "i want these errors to bork everything" | |
raise "BEFORE" | |
begin | |
raise "AFTER" | |
rescue => e | |
puts "I'll handle these errors specially" | |
puts "#{e}" | |
end | |
end |