Ruby is amazing. It has a huge standard library and a core choc full of weird and wonderful things. In this talk, given at the Ipswich Ruby User Group, I give a whimsical nonstop tour through some of the more obscure parts of Ruby.
8. STRING
#squeeze
“Uh oh the cat sat on the keeeeeeeeeee”.squeeze
=>
“Uh oh the cat sat on the ke”
“oh craaaapppp my aaappp keys are bloody
broken”.squeeze(“ap”)
=>
“oh crap my ap keys are bloody broken”
9. STRING
#count
“FINISHED FILES ARE THE RE-
SULT OF YEARS OF SCIENTIF-
IC STUDY COMBINED WITH
THE EXPERIENCE OF YEARS.”
How many F’s are there?
10. STRING
#count
“FINISHED FILES ARE THE RE-
SULT OF YEARS OF SCIENTIF-
IC STUDY COMBINED WITH
THE EXPERIENCE OF YEARS.”.count(“F”)
=>
6
11. STRING
#count
“how many woods would a wood chuck chuck if a
wood chuck could chuck wood?”.count(“a-z”, “^u”)
=>
52
26. RSS
require ‘rss/2.0’
response = open(http://feeds.feedburner.com/MrjabasAdventures).read
rss = RSS::Parser.parse(response, false)
rss.items.each do |item|
p item.title
end
27. MiniTest
require ‘minitest/autorun’
describe Cheese do
before do
@cheddar = Cheese.new(“cheddar”)
end
describe when enquiring about smelliness do
it must respond with a stink factor do
@cheddar.smelliness?.must_equal 0.9
end
end
end
Provides:
Specs Mocking Stubbing Runners Benchmarks