Skip to content

Instantly share code, notes, and snippets.

View JEG2's full-sized avatar

James Edward Gray II JEG2

View GitHub Profile
class Rectangle
def initialize(width, height)
@width = width
@height = height
end
def area
@width * @height
end
end
##########################
### Regular Expression ###
##########################
# Ruby is very good at dissecting data. The reason for that is that Matz
# elected to not only include a mini language used for pattern matching, but
# more importantly to treat it as a first class citizen inside Ruby. This mini
# language is called Regular Expression.
# There are many advantages to learning to use Regular Expressions. Some tasks
#############
### Regex ###
#############
# Build regular expressions to match each of the following:
#
# 1. An IP address. Use the format N.N.N.N, where each N is an Integer between
# 0 and 255. Don't allow numbers outside that range. There aren't always
# three digits either. For example, the loopback address for your computer
# is 127.0.0.1.
Testing Gist posting from Vim.
require "date"
require "digest/sha2"
require "pathname"
require "time"
require "uri"
require "rubygems"
require "rufus/tokyo"
class OklahomaMixer
require "twitter"
require "sunlight"
data_pos = DATA.pos
last_id = DATA.read.to_s[/\d+/]
last_id = last_id.to_i if last_id
DATA.reopen(__FILE__, "a+")
Twitter.configure do |config|
class Thing
def verb
"Do something"
end
end
module Modified
def verb
"#{super} else"
end
# I see code like this all the time:
def get_results
if have_results?
return results # an Enumerable object
else
nil
end
end
def closure_with_state(start, multiplier)
i = -1
current = nil
lambda { current = start * (multiplier * (i += 1)) }
end
doubles = closure_with_state(1, 2)
triples = closure_with_state(1, 3)
p Array.new(10) { doubles.call }
def testing_gist
puts "Welcome to the future"
end