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 DumbSearch | |
def initialize(min, max) | |
#@min = min | |
#@max = max | |
@guessed = false | |
@next_guess = 50 | |
end | |
attr_reader :next_guess, :guessed |
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
s = "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way – in short, the period was so far like the present period, that some of its noisiest authorities insisted on its being received, for good or for evil, in the superlative degree of comparison only." | |
vowels = %w{a e i o u} | |
vowels.each_with_index do |vowel, index| | |
s.gsub!(vowel,"SUB#{index}SUB") | |
end | |
vowels.each_with_index do |vowel, index| | |
s.gsub!("SUB#{index}SUB", vowels[(index+1)%vowels.length]) | |
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
#Dear Test Actually attendees | |
My talk at Test Actually (on the 16th of August, 2017), will include some live bug fixing. | |
I already have an app which is rich in bugs and glitches, but no bug reports to work from. | |
You can help! | |
Feel free to find an issue in my app, a simple inventory tracker for a library, which may be used in the talk. | |
(You will need a GitHub account) |
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
# found with ruby 2.2.2 (but I think it must have worked on 1.9, too. | |
def meth(arg) | |
argument.is_a?(String) ? 'a' : 'b' | |
end | |
meth('foo') | |
# NameError: undefined local variable or method `argument' for main:Object | |
# This is completely expected, I've never defined `argument`. |
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 meth | |
if false | |
puts 'not here' | |
end | |
else | |
puts 'WAT' | |
end | |
# warning: else without rescue is useless | |
meth |
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
> u.memberships.any? | |
# (2.9ms) SELECT COUNT(*) FROM "MEMBERSHIPS" WHERE "MEMBERSHIPS"."USER_ID" = 10080 | |
# => true | |
> u.memberships.none? | |
# Membership Load (2.4ms) SELECT "MEMBERSHIPS".* FROM "MEMBERSHIPS" WHERE "MEMBERSHIPS"."USER_ID" = 10080 ORDER BY team_id | |
# Team Load (6.0ms) SELECT "TEAMS".* FROM "TEAMS" WHERE "TEAMS"."ID" IN (1) | |
# => false | |
# The any? method is counting the number of memberships, then presumably asking in Ruby if the number is more than 1. |
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 my_method | |
puts 'original' | |
end | |
end | |
module Bar | |
def my_method | |
puts 'overridden' | |
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
# How can this line throw an error? | |
@folder = object.respond_to?(:project_element) ? object.project_element : nil | |
# The error is this: | |
# undefined method `project_element' for #<Report::Event:0x007fbb6eb8ca78> | |
# Surely This should be protected, right? | |
# ----------------------------- |
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
require 'rspec' | |
describe 'something' do | |
it 'should know what valid means' do | |
record = Object.new | |
record.should be_valid? | |
# undefined method 'valid??' for #<Object#0x0000000f453d063> | |
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
$('body').on( | |
'click', | |
'a#my_element', | |
function(e) { | |
e.preventDefault(); | |
$('body').on( | |
'click', | |
'a#my_element', | |
function(e) { | |
e.preventDefault(); |