Skip to content

Instantly share code, notes, and snippets.

View Supernats's full-sized avatar

Nathan Seither Supernats

View GitHub Profile
<p>
<%= "Husband: #{husband}" %>
<%= "Wife: #{ begin; husband.wife; rescue NoMethodError; end}" %>
<%= "Status: #{ begin; husband.wife.status; rescue NoMethodError; end}" %>
</p>
module StringAppleization
refine String do
def appleize
split(' ').map do |word|
appleize_word(word)
end.join(' ')
end
private
module Refinements::StringNumericalConversions
refine String do
def to_integer
banana
Integer(self)
rescue ArgumentError
nil
end
private
[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
class Wrapper
attr_reader :string
def initialize(string)
@string = string
end
def upcase!
string.upcase!
end
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
@Supernats
Supernats / poop
Last active October 2, 2015 00:04
~/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
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
class RedisModel::Base
attr_reader :source, :target
def initialize(source:, target:)
@source = source
@target = target
end
class << self
def all
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