Eureka, "Small Town, Big Secrets"
My brother Andrew's new TV series EUReKA premieres July 18 @ 9/8C on the SCIFI channel.
Think 'Twin Peaks' meets 'Mayberry RFD'.
Don't miss it! Tell your friends. If you're a SCIFI geek, tell your enemies too.
My brother Andrew's new TV series EUReKA premieres July 18 @ 9/8C on the SCIFI channel.
"It's a little known fact among those in the know
that on one night each year when the howling winds blow
if you stay up past bedtime 'til thirteen past three
there's a place not like this place you're likely to see."
"Welcome to Nocturnia, home to nightmares, monsters, and one little misfit named Edgar Grimm. Like most kids, Ed would love to make his parents proud. For Ed that means following in the big, frightful footprints of his dad, who just happens to be the Bogeyman! Unfortunately, unlike his famous father, Ed's not very scary. You see, Ed isn't like the other monsters his age. In fact, he isn't a monster at all... but that won't stop him from trying to prove that even a good little boy can find a place among the biggest, baddest monsters there are."
Maybe one of the reasons inheritance is so overused in certain static languages like Java and C# is that it can be a pain in the ass to write those tiny methods that hand off operations to the delegate class.
class ShuffleArray < Array
def shuffle
sort_by { rand }
end
end
class CardDeck
alias :method_missing_orig :method_missing
def initialize(cards)
@cards = ShuffleArray.new(cards)
end
def method_missing(m, *args, &block)
if @cards.respond_to?(m)
@cards.send(m, *args, &block)
else
method_missing_orig(m, *args, &block)
# or you could just raise the exception or return nil
# raise NoMethodError
end
end
end
class Card
attr_reader :face, :suit
def initialize(face, suit)
@face, @suit = face, suit
end
def to_s
puts "#{face} of #{suit}"
end
end
aos = Card.new("Ace", "Spades")
kod = Card.new("King", "Diamonds")
qoh = Card.new("Queen", "Hearts")
joc = Card.new("Jack", "Clubs")
cards = [aos, kod, qoh, joc]
card_deck = CardDeck.new(cards)
irb(main):041:0> puts card_deck.size
4
=> nil
irb(main):042:0> card_deck.each {|card| puts card }
Ace of Spades
#<Card:0x2c1d510>
King of Diamonds
#<Card:0x2c19820>
Queen of Hearts
#<Card:0x2c15c08>
Jack of Clubs
#<Card:0x2c12170>
=> [#<Card:0x2c1d510 @suit="Spades", @face="Ace">,
#<Card:0x2c19820 @suit="Diamonds", @face="King">,
#<Card:0x2c15c08 @suit="Hearts", @face="Queen">,
#<Card:0x2c12170 @suit="Clubs", @face="Jack">]
irb(main):043:0> puts card_deck[3]
Jack of Clubs
#<Card:0x2c12170>
=> nil
irb(main):044:0> cards_shuffled = card_deck.shuffle
=> [#<Card:0x2c15c08 @suit="Hearts", @face="Queen">,
#<Card:0x2c1d510 @suit="Spades", @face="Ace">,
#<Card:0x2c19820 @suit="Diamonds", @face="King">,
#<Card:0x2c12170 @suit="Clubs", @face="Jack">]
irb(main):046:0> cards_shuffled = card_deck.shuffle
=> [#<Card:0x2c12170 @suit="Clubs", @face="Jack">,
#<Card:0x2c15c08 @suit="Hearts", @face="Queen">,
#<Card:0x2c1d510 @suit="Spades", @face="Ace">,
#<Card:0x2c19820 @suit="Diamonds", @face="King">]
irb(main):050:0> cards_shuffled = card_deck.shuffle
=> [#<Card:0x2c1d510 @suit="Spades", @face="Ace">,
#<Card:0x2c12170 @suit="Clubs", @face="Jack">,
#<Card:0x2c19820 @suit="Diamonds", @face="King">,
#<Card:0x2c5c08 @suit="Hearts", @face="Queen">]
irb(main):051:0> card_deck.find {|c| c.face == "Ace" }
=> #<Card:0x2c1d510 @suit="Spades", @face="Ace">
irb(main):052:0> card_deck.reverse
=> [#<Card:0x2c12170 @suit="Clubs", @face="Jack">,
#<Card:0x2c15c08 @suit="Hearts", @face="Queen">,
#<Card:0x2c19820 @suit="Diamonds", @face="King">,
#<Card:0x2c1d510 @suit="Spades", @face="Ace">]
irb(main):053:0> card_deck.sort_by { |c| c.suit }
=> [#<Card:0x2c12170 @suit="Clubs", @face="Jack">,
#<Card:0x2c19820 @suit="Diamonds", @face="King">,
#<Card:0x2c15c08 @suit="Hearts", @face="Queen">,
#<Card:0x2c1d510 @suit="Spades", @face="Ace">]