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 Itinerary | |
| class Day | |
| def initialize(date,&block) | |
| @date = date | |
| instance_eval(&block) | |
| end | |
| def readings | |
| @readings ||= Array.new | |
| 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
| # script to build a web page that shows the links contained on pages at source urls | |
| # an example solution for the question at http://www.ruby-forum.com/topic/521021 | |
| # if these change frequently, it might be better to read them from a file | |
| # rather than store them in the source | |
| urls = [ | |
| 'http://www.google.com/', | |
| 'http://weatherflash.com/usa/ks/wichita/', | |
| 'http://umbrellatoday.com/', |
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 exp_and_msg | |
| return 1 , "hi" | |
| end | |
| exp , msg = exp_and_msg | |
| exp # => 1 | |
| msg # => "hi" |
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
| #!/usr/bin/env ruby | |
| # probably need to $ gem install doublehelix | |
| require "doublehelix" | |
| GC | |
| A--T | |
| C---G | |
| G----C | |
| A----T |
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
| switch = 0 | |
| stay = 0 | |
| 100_000.times do | |
| doors = [ :goat , :goat , :goat , :car ].shuffle | |
| guess = rand doors.size | |
| if doors[guess] == :car | |
| stay += 1 |
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
| switch = 0 | |
| stay = 0 | |
| 100_000.times do | |
| doors = [ :goat , :goat , :goat , :car ].shuffle | |
| guess = rand doors.size | |
| if doors[guess] == :car | |
| stay += 1 |
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
| # While watching Rick DeNatale's talk at RubyConf | |
| # http://confreaks.net/videos/461-rubyconf2010-objects-are-just-objects-aren-t-they | |
| # he shows how SICP introduces cons as lambdas. | |
| # I thought the idea was interesting, so decided to try it out. Done here in Ruby. | |
| def cons head , tail | |
| cons = ->(which) { which == :head ? head : tail } | |
| def cons.inspect(is_head=true) | |
| car = car(self).inspect | |
| cdr = cdr(self).inspect |
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
| # http://www.ruby-forum.com/topic/860689 | |
| def ask question | |
| goodAnswer = false # The Ruby idiom is to use snake_case for variables | |
| while (not goodAnswer) # here, I would say "until goodAnswer" | |
| puts question | |
| response = gets.chomp | |
| attack = rand(11) | |
| attacker = rand(11) |
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
| --- | |
| - :category: cat1 | |
| :items: | |
| - item1 | |
| - item2 | |
| - item3 | |
| - :category: cat2 | |
| :items: | |
| - item1 | |
| - :category: cat3 |
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
| # Lets create a simple calculator app together, it should have a get method for localhost:4567/calculator that displays two forms | |
| # the first form should post (note that post is one of those http methods) to localhost:4567/add, and have two fields named "num1" and "num2" | |
| # the second form should post to localhost:4567/subtract with the same args | |
| # the page that they go to should display the result, and have a link to get back to calculator | |
| require 'rubygems' | |
| require 'sinatra' | |
| get '/calculator' do | |
| ' |