This file contains hidden or 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 foo | |
end |
This file contains hidden or 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
# This is my gist |
This file contains hidden or 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
import org.apache.http.client._ | |
import org.apache.http.client.methods._ | |
import org.apache.http.impl.client._ | |
import scala.xml._ | |
object S { | |
def main(args : Array[String]) : Unit = { | |
val root = scala.xml.XML.load((new DefaultHttpClient).execute ( | |
new HttpGet("http://whoismyrepresentative.com/getall_sens_bystate.php?state="+args.head) | |
).getEntity.getContent) |
This file contains hidden or 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 MorseEncoder | |
TRANSLATIONS = { | |
:a => "._", | |
:b => "_...", | |
:c => "_._.", | |
:d => "_..", | |
:e => "." | |
} | |
def method_missing(m, *args) |
This file contains hidden or 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
# use .each (or each_with_index) and iteration to implement these | |
array_of_numbers = [1,2,3,4,5] | |
number_to_add = 2 | |
puts array_of_numbers.add_a_number_to_each_of_these_numbers(number_to_add) | |
# => [3, 4, 5, 6, 7] | |
list = [:name, 'Chad', :place, 'Virginia'] | |
list.turn_into_hash |
This file contains hidden or 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
#https://gist.github.com/786350 | |
module Names | |
def self.included(klass) | |
klass.extend ClassLevelMethods | |
klass.send(:attr_reader, :displayed_attribute_info) | |
end | |
def to_s | |
"<#{self.class.name} " + | |
self.class.displayed_attribute_info.map do |attr_name, label| |
This file contains hidden or 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 Names | |
# TODO | |
end | |
Object.send(:include, Names) | |
class Person | |
displayed_attribute :name | |
displayed_attribute :age | |
displayed_attribute :ssn, :label => "Social Security Number" |
This file contains hidden or 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 LoggerClass | |
def self.attr_logger(attribute_name) | |
class_eval "def #{attribute_name}; @#{attribute_name}; end" | |
class_eval "def #{attribute_name}=(val); @#{attribute_name} = val; end" | |
end | |
end | |
class Person < LoggerClass | |
attr_logger :age | |
attr_logger :name |
This file contains hidden or 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 LoggerClass | |
def self.attr_logger(attribute_name) | |
iv_name = "@#{attribute_name}" | |
define_method(attribute_name) do | |
instance_variable_get(iv_name) | |
end | |
define_method("#{attribute_name}=") do |value| | |
STDERR.puts "setting #{attribute_name} to #{value}" | |
instance_variable_set(iv_name, value) | |
end |
This file contains hidden or 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 Vocal | |
def speak | |
puts "#{self} says hello" | |
end | |
end | |
class Object | |
def ekstend(mod) | |
class << self | |
self |