This repository was archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
week 9 gem uploaded - jonas haskins #119
Open
sanojsniksah
wants to merge
26
commits into
UWE-Ruby:master
Choose a base branch
from
sanojsniksah:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+848
−96
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e15fe96
finished the homework!
7e6e8be
my homework
8c7cb8c
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
8f4539f
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
1dfb52e
Finished the homework questions, and the simon_says.rb module for hom…
sanojsniksah 99b604b
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 433e2fe
my book exe
sanojsniksah 3d0172c
spec file.
sanojsniksah 0fc7874
exercises and stuff ...
sanojsniksah a2085b7
homework ! jonas haskins week 3
sanojsniksah 2d2a8d3
Merge github.com:UWE-Ruby/RubyFall2013
sanojsniksah 72c3def
Merge github.com:UWE-Ruby/RubyFall2013
sanojsniksah a52c98b
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 24c4b92
Initial commit
sanojsniksah a909850
Created the new depo and added the instructions to get started.
sanojsniksah 24496d5
first draft of working even numbers and even numberes spec.
sanojsniksah 65dc743
Merge branch 'master' of github.com:sanojsniksah/jonashaskins_midterm
sanojsniksah 761d1b1
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 8816f5d
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 978f2c2
homework for week 7
sanojsniksah 25791bd
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 767bfa4
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 3e357cf
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2013
sanojsniksah 2b2f5ae
added all these goodies and the .travis.yml
sanojsniksah d0378b1
fixed a issue with .travis.yml
sanojsniksah e2d9429
added my gem.
sanojsniksah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: ruby | ||
rvm: | ||
- "1.8.7" | ||
- "1.9.2" | ||
- "1.9.3" | ||
- jruby-18mode # JRuby in 1.8 mode | ||
- jruby-19mode # JRuby in 1.9 mode | ||
- rbx-18mode | ||
# uncomment this line if your project needs to run something other than `rake`: | ||
# script: bundle exec rspec spec |
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
File renamed without changes.
File renamed without changes.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
describe "NamePrinter Application" do | ||
|
||
context "When Somethings Happens When I'm Logged In" do | ||
it "should say Something" do | ||
"Something".should eq "Something" | ||
end | ||
end | ||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,47 @@ | ||
Please read: | ||
Chapter 3 Classes, Objects, and Variables | ||
|
||
p.86-90 Strings (Strings section in Chapter 6 Standard Types) | ||
|
||
1. What is an object? | ||
a instance of a class. | ||
|
||
2. What is a variable? | ||
a reference to a object | ||
|
||
3. What is the difference between an object and a class? | ||
a class is a combination of state and methods. an object is a instance of that class ( class instance ). | ||
|
||
|
||
4. What is a String? | ||
A sequence of characters. | ||
|
||
5. What are three messages that I can send to a string object? Hint: think methods | ||
chomp, count, delete, empty? , length, upcase, downcase, split, squeeze! ... woah there are alot. | ||
|
||
|
||
6. What are two ways of defining a String literal? Bonus: What is the difference between the two? | ||
|
||
single or double quotation marks. | ||
|
||
single quotes 'foo', foo becomes the value. | ||
For Double quotes, "foo\nbar" ruby looks for substitutions, interpolation "#{foo}" and escape sequences "Foo \nBar" | ||
|
||
also %q ( single quotes ), %Q ( double quotes ) | ||
|
||
%q/foo bar/ | ||
%Q!oh no #{crap}! | ||
|
||
you can choose a delimiter. | ||
|
||
Finally here documents. | ||
|
||
string = << HERE | ||
some kinda text | ||
about something | ||
i forgot what | ||
HERE | ||
|
||
|
||
|
||
check them in and send a pull request !! |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# encoding: utf-8 | ||
|
||
# Please make these examples all pass | ||
# You will need to change the 3 pending tests | ||
# You will need to write a passing test for the first example | ||
# (Hint: If you need help refer to the in-class exercises) | ||
# The two tests with the pending keyword, require some ruby code to be written | ||
# (Hint: You should do the reading on Strings first) | ||
|
||
describe String do | ||
context "When a string is defined" do | ||
before(:all) do | ||
@my_string = "Renée is a fun teacher. Ruby is a really cool programming language" | ||
end | ||
it "should be able to count the charaters" | ||
it "should be able to split on the . charater" do | ||
pending | ||
result = #do something with @my_string here | ||
result.should have(2).items | ||
end | ||
it "should be able to give the encoding of the string" do | ||
pending 'helpful hint: should eq (Encoding.find("UTF-8"))' | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def count_frequency(word_list) | ||
counts = Hash.new(0) | ||
for word in word_list | ||
counts[word] += 1 | ||
end | ||
counts | ||
end | ||
|
||
p count_frequency(["sparky", "the", "cat", "sat", "on", "the", "mat"]) |
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
puts "Please enter a noun" | ||
print "Please enter a noun : " | ||
noun = gets.chomp | ||
puts "Please enter an adjective" | ||
print "Please enter an adjective : " | ||
adjective = gets.chomp | ||
puts "Please enter a past tense action verb" | ||
print "Please enter a past tense action verb : " | ||
verb_past_tense = gets.chomp | ||
puts "What does the #{noun} say?" | ||
print "What does the #{noun} say? : " | ||
says = gets.chomp | ||
story = "The #{adjective} #{noun} #{verb_past_tense} past the graveyard and says #{says}" | ||
puts story |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
describe Book do | ||
|
||
context |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module SimonSays | ||
def echo(says) | ||
@says = says | ||
end | ||
|
||
def shout(shouts) | ||
@shouts = shouts | ||
@shouts.upcase | ||
end | ||
|
||
def repeat(word, *times) | ||
@word = word | ||
@times = times[0] | ||
if @times == nil | ||
@times = 2 | ||
end | ||
@word = "#{@word} " * @times | ||
@word.rstrip | ||
end | ||
|
||
def start_of_word(word, number) | ||
a = word.split(//) | ||
number = number - 1 | ||
b = a[0..number] | ||
b.join | ||
end | ||
|
||
def first_word(word) | ||
a = word.split(/ /) | ||
a[0] | ||
end | ||
|
||
end | ||
|
||
# Question .. is it correct to use instance variables here as in for | ||
# echo/shout/repeat methods or better ( more ruby?? ) to use | ||
# as in start_or_word and first_word ?? | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require_relative 'count_frequency' | ||
require 'test/unit' | ||
|
||
class TestCountFrequency < Test::Unit::TestCase | ||
def test_empty_list | ||
assert_equal({}, count_frequency([])) | ||
end | ||
def test_single_word | ||
assert_equal({"cat" => 1}, count_frequency(["cat"])) | ||
end | ||
def test_two_different_words | ||
assert_equal({"cat" => 1, "sat" => 1}, count_frequency(["cat", "sat"])) | ||
end | ||
def test_two_words_with_adjacent_repeat | ||
assert_equal({"cat" => 2, "sat" => 1}, count_frequency(["cat", "cat", "sat"])) | ||
end | ||
def test_two_words_with_non_adjacent_repeat | ||
assert_equal({"cat" => 2, "sat" => 1}, count_frequency(["cat", "sat", "cat"])) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def words_from_string(string) | ||
string.downcase.scan(/[\w']+/) | ||
end | ||
|
||
p words_from_string("But I didn't inhale, he said (emphatically)") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
1.9.3-p392 :001 > load 'monsters.rb' | ||
=> true | ||
1.9.3-p392 :002 > $monsters.count{|m| m[:nocturnal]} | ||
=> 2 | ||
1.9.3-p392 :005 > $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]} | ||
=> ["Vampire", "Werewolf"] | ||
|
||
1.9.3-p392 :007 > $monsters.select{|m| m[:nocturnal]}.map{|m| m[:name]} | ||
=> ["Vampire", "Werewolf"] | ||
|
||
1.9.3-p392 :009 > legs = 0 | ||
=> 0 | ||
|
||
1.9.3-p392 :011 > $monsters.each{|m| legs += m[:legs]} | ||
=> [{:name=>"Zombie", :nocturnal=>false, :dangers=>["bites", "scratches"], :vulnerabilities=>["fire", "decapitation"], :legs=>2}, {:name=>"Mummy", :nocturnal=>false, :dangers=>["bites", "scratches", "curses"], :vulnerabilities=>["fire", "decapitation", "cats"], :legs=>2}, {:name=>"Vampire", :nocturnal=>true, :dangers=>["bites", "hypnosis"], :vulnerabilities=>["wood", "decapitation", "crosses", "holy_water", "garlic", "daylight"], :legs=>2}, {:name=>"Werewolf", :nocturnal=>true, :dangers=>["bites", "scratches"], :vulnerabilities=>["silver"], :legs=>4}, {:name=>"Blob", :nocturnal=>false, :dangers=>["suffocation"], :vulnerabilities=>["CO2", "ice", "cold"], :legs=>0}] | ||
1.9.3-p392 :012 > legs | ||
=> 10 | ||
1 | ||
|
||
counts the legs. shorthand. adds ( sum ) numbers in the array. | ||
$monsters.map{|m| m[:legs]}.inject(:+) | ||
|
||
|
||
|
||
1.9.3-p392 :031 > dangers.inject(Hash.new(0)){|hist, danger| hist[danger]+=1 ;hist} | ||
=> {["bites", "scratches"]=>2, ["bites", "scratches", "curses"]=>1, ["bites", "hypnosis"]=>1, ["suffocation"]=>1} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
require './named_thing.rb' | ||
class Monster | ||
|
||
class Monsters | ||
include NamedThing | ||
attr_accessor :vulnerabilities, :dangers | ||
attr_reader :nocturnal, :legs | ||
|
||
def initialize(noc, legs, name="Monster", vul = [], dangers = []) | ||
super(name) | ||
@nocturnal = noc | ||
@vlunerabilities = vul | ||
attr_accessor :names, :legs, :dangers, :vulnerabilities, :nocturnal | ||
|
||
def initialize legs, nocturnal, name="Monster", dangers=[], vulnerabilities=[] | ||
@leg = legs | ||
@nocturnal = nocturnal | ||
@dangers = dangers | ||
@legs = legs | ||
@vulnerabilities = vulnerabilities | ||
super name | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
require './monster.rb' | ||
|
||
class Vampire < Monster | ||
def initialize(noc=true, legs=2, name ="Vampire", vul=[:garlic, :sunlight], dangers=[:bites]) | ||
super(noc,legs,name,vul,dangers) | ||
|
||
def initalize legs = 2, nocturnal = true, name = "Vampire", dangers = [:bites] , vulnerabilities = [:sunlight, :garlic] | ||
super | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# au jonas haskins | ||
class Calculator | ||
def sum(digits) | ||
digits.inject 0, :+ | ||
end | ||
|
||
def pow(v1, v2) | ||
p = 1 | ||
v2.times{ p *= v1 } | ||
power = p | ||
end | ||
|
||
def multiply(*nums) | ||
nums.flatten.inject(:*) | ||
end | ||
|
||
def fac(number) | ||
(1..number).inject(:*) || 1 | ||
end | ||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module DoWork | ||
attr_accessor :work | ||
|
||
def initialize work | ||
@work = work | ||
end | ||
|
||
#def shout_name | ||
# @name.upcase | ||
#end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
'br.retsnom/.' eriuqer | ||
|
||
retsnoM < eripmaV ssalc | ||
|
||
]cilrag: ,thgilnus:[ = seitilibarenluv ,]setib:[ = sregnad ,"eripmaV" = eman ,eurt = lanrutcon ,2 = sgel ezilaitini fed | ||
repus | ||
dne dne |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Worker | ||
def self.work x=1 | ||
if x == 1 | ||
yield | ||
else | ||
x = x - 1 | ||
x += yield | ||
|
||
end | ||
end | ||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#class Worker | ||
# # this is a class level method | ||
# def self.work x=1 | ||
# if x == 1 | ||
# yield | ||
# else | ||
# x = x - 1 | ||
# x += yield | ||
# | ||
# end | ||
# end | ||
#end | ||
|
||
|
||
|
||
# class anserr | ||
#class Worker | ||
# # this is a class level method | ||
# def self.work n=1 | ||
# results = nil | ||
# n.times { results = yield } | ||
# results | ||
# end | ||
#end | ||
|
||
|
||
# teachers answer | ||
class Worker | ||
# this is a class level method | ||
def self.work n=1 | ||
n.times.inject(nil){yield} | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "#{File.dirname(__FILE__)}/worker" | ||
|
||
describe Worker do | ||
|
||
it "executes a block and returns a string" do | ||
result = Worker.work do | ||
"hello" | ||
end | ||
result.should == "hello" | ||
end | ||
|
||
it "executes a block and returns a number" do | ||
result = Worker.work do | ||
3 + 4 | ||
end | ||
result.should == 7 | ||
end | ||
|
||
it "executes a block in the context of the calling method" do | ||
n = 1 | ||
result = Worker.work do | ||
n + 4 | ||
end | ||
result.should == 5 | ||
end | ||
|
||
|
||
it "executes a block 3 times and returns the result" do | ||
n = 5 | ||
result = Worker.work(3) do | ||
n += 1 | ||
end | ||
result.should == 8 | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CodeTimer | ||
def self.time_code n=1 | ||
start_time = Time.now | ||
n.times { yield } | ||
Time.now - start_time | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
worker_spec.rb | ||
|
||
questions file. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require './code_timer.rb' | ||
|
||
describe CodeTimer do | ||
|
||
it "should run our code" do | ||
flag = false | ||
|
||
CodeTimer.time_code do | ||
flag = true | ||
end | ||
|
||
flag.should eq true | ||
|
||
end | ||
|
||
it "should time our code" do | ||
|
||
Time.stub(:now).and_return(0,3) | ||
run_time = CodeTimer.time_code do | ||
end | ||
|
||
run_time.should be_within(0.1).of(3.0) | ||
end | ||
|
||
it "should run our code mult times " do | ||
i = 0 | ||
CodeTimer.time_code(10){ i+=1 } | ||
i.should eq 10 | ||
end | ||
|
||
it "should give us the average time " do | ||
run_time = CodeTimer.time_code(10) { | ||
sleep(1) | ||
} | ||
run_time.should be_within(0.1).of(1.0) | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
task :default => [:hello_world] | ||
|
||
desc "This is the hellow worrld script" | ||
task :eatit do | ||
puts File.read("names") | ||
end | ||
|
||
task :mkdir do | ||
Dir.mkdir("Class") | ||
end | ||
|
||
task : create_student_dirs => [:create_class_dir ]do | ||
Dir.chdir('Class') | ||
File.open("../names") do |f| | ||
f.map{|line| Dir.mkdir line.chomp} | ||
end | ||
end | ||
|
||
task : create_student_dirs => [:create_class_dir ]do | ||
Dir.chdir('Class') | ||
File.open("../names") do |f| | ||
f.map{|line| Dir.mkdir line.chomp} | ||
end | ||
end | ||
|
||
def file_helper(file_name) | ||
File.open(file_name) do |f| | ||
f.each do |line| | ||
yield line.chomp | ||
end | ||
end | ||
end |
Submodule sanoj
added at
434d47
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Given(/^I have entered (\d+) into the converter$/) do |arg1| | ||
# pending # express the regexp above with the code you wish you had | ||
@temp | ||
end | ||
|
||
Given(/^I set the type to Fahrenheit$/) do | ||
# pending # express the regexp above with the code you wish you had | ||
@type = 'Fahrenheit' | ||
end | ||
|
||
When(/^I press convert$/) do | ||
|
||
end | ||
|
||
Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2| | ||
#pending # express the regexp above with the code you wish you had | ||
class Convert | ||
def self | ||
n = (@temp - 32) * 5 / 9 | ||
n.round(1) | ||
end | ||
end | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Converter | ||
|
||
attr_writer :type | ||
|
||
def initalize celcius_value | ||
@value = celcius_value.to_f | ||
end | ||
|
||
|
||
def convert | ||
((@value - 32 ) * (5.0 / 9.0)).round(1) | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class PirateTranslator | ||
attr_accessor :split | ||
|
||
|
||
def say(what) | ||
@what = what | ||
end | ||
|
||
def translate | ||
if ( @what =~ /Hello Friend/) | ||
@what = 'Ahoy Matey' + "/n Shiber Me Timbers You Scurvey Dogs!!" | ||
end | ||
end | ||
|
||
# can't figger out how to return a array of them both? | ||
# this isn;t right. | ||
def speak | ||
@arr = 'Shiber Me Timbers You Scurvey Dogs!!' | ||
@speak_a.push("@what", "@arr") | ||
@speak = speak.a.join(/\n /) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class PirateTranslator | ||
attr_accessor :split | ||
|
||
PIRATE_WORDS = { | ||
hello_friend: "Ahoy Matey" | ||
} | ||
|
||
def say(what) | ||
@what = what | ||
end | ||
|
||
def translate | ||
pirate_lookup @said + "\n Awh shiver me timbers " | ||
end | ||
|
||
|
||
private | ||
|
||
def pirate_lookup said | ||
key = said.gsub(' ' , '_').downcase | ||
PIRATE_WORDS[key] | ||
end | ||
|
||
|
||
|
||
def translate | ||
if ( @what =~ /Hello Friend/) | ||
@what = 'Ahoy Matey' | ||
end | ||
end | ||
|
||
# can't figger out how to return a array of them both? | ||
# this isn;t right. | ||
def speak | ||
@arr = 'Shiber Me Timbers You Scurvey Dogs!!' | ||
@speak_a.push("@what", "@arr") | ||
@speak = speak.a.join(/\n /) | ||
end | ||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## |
1 change: 1 addition & 0 deletions
1
week7/homework/features/step_definitions/rspec/mocks/standalone.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,30 @@ Please Read Chapters 23 and 24 DuckTyping and MetaProgramming | |
|
||
Questions: | ||
1. What is method_missing and how can it be used? | ||
it's a method, called method_missing. | ||
|
||
it can by used to intercept the use of a undefined method and handle it. | ||
you can also use it to intercept all the calls to methods, but only handle | ||
some of them ( glob? ) | ||
|
||
|
||
2. What is and Eigenclass and what is it used for? Where Do Singleton methods live? | ||
A eigenclass is a hidden class associated with each specific instance of another class.. | ||
|
||
Singleton methods are specific to a single object. | ||
They are defined on the object it's self and not the class. | ||
Usually they are defined in a Eigenclass. | ||
|
||
|
||
3. When would you use DuckTypeing? How would you use it to improve your code? | ||
if you were coding in C# or Java or Perl. Readability?. I did Perl in DuckTyping. | ||
I wouldn't use it in Ruby. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You pretty much always use DuckTypeing, in that it's not necessary to declare types for objects in Ruby. It makes code more flexible and easier to maintain. The focus is on testing the capabilities of an object instead of its type. |
||
|
||
4. What is the difference between a class method and an instance method? What is the difference between instance_eval and class_eval? | ||
Class methods are methods that are called on a class, and instance methods are methods that are called on a instance of a class. | ||
instance_eval defines class methods and class_eval defines instance methods. | ||
|
||
5. What is the difference between a singleton class and a singleton method? | ||
|
||
a singleton method is a method that is defined only for a single object, | ||
and a singleton class is defined ON the object. |
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
Submodule Songsoftheday
added at
e39e3c
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# how your doing something in a method | ||
# something tied to sepcifics .. | ||
# carefull about putting votile info in comments | ||
# change code , don' t update the comments. | ||
# that is bad ... |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# exception example | ||
#class JonasError < Exception | ||
# def message | ||
# "its messed up " | ||
# end | ||
#end | ||
|
||
#begin | ||
|
||
#raise "AGGGG" | ||
# raise JonasError.new | ||
|
||
#puts 0/1 | ||
|
||
# f = File.open('hello.txt') | ||
# f.close | ||
# f.read | ||
#rescue => e | ||
##rescue => e | ||
# puts e | ||
# puts e.class | ||
#rescue IOError => e | ||
# puts "there was a io error" | ||
#ensure | ||
# puts "hello world" | ||
#end | ||
# | ||
# | ||
catch :yipes do | ||
|
||
i = 0 | ||
while i<10 | ||
sleep (2) and throw :yipes if i == 5 | ||
puts i+=1 | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'sinatra' | ||
require 'sinatra/reloader' | ||
require 'puma' | ||
|
||
get '/' do | ||
"<html> | ||
<body> | ||
<h1><fint color='pink'>HI<</font></h1> | ||
<center> | ||
</body> | ||
</html>" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
jonashaskins@zadmins-MacBook-Pro-2~/RUBY_CLASS/RubyFall2013/week9$ irb | ||
1.9.3p392 :001 > Dog = Struct.new(:name, :owner, :age) | ||
=> Dog | ||
1.9.3p392 :002 > d = Dog.new('Bradley', 'Jonas', '6') | ||
=> #<struct Dog name="Bradley", owner="Jonas", age="6"> | ||
1.9.3p392 :003 > d.name | ||
=> "Bradley" | ||
1.9.3p392 :004 > d.age | ||
=> "6" | ||
1.9.3p392 :005 > d.owner | ||
=> "Jonas" | ||
1.9.3p392 :006 > d.name = "Rockey the Dog" | ||
=> "Rockey the Dog" | ||
1.9.3p392 :007 > d.name | ||
=> "Rockey the Dog" | ||
1.9.3p392 :008 > d.age = '100' | ||
=> "100" | ||
1.9.3p392 :009 > d.age | ||
=> "100" | ||
1.9.3p392 :010 > | ||
|
||
1.9.3p392 :016 > d.each_pair do |i| | ||
1.9.3p392 :017 > puts i | ||
1.9.3p392 :018?> end | ||
name | ||
owner | ||
age | ||
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100"> | ||
1.9.3p392 :019 > d.each_pair{|k,v| puts k} | ||
name | ||
owner | ||
age | ||
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100"> | ||
1.9.3p392 :020 > | ||
|
||
|
||
|
||
|
||
jonashaskins@zadmins-MacBook-Pro-2~/RUBY_CLASS/RubyFall2013/week9$ irb | ||
1.9.3p392 :001 > Dog = Struct.new(:name, :owner, :age) | ||
=> Dog | ||
1.9.3p392 :002 > d = Dog.new('Bradley', 'Jonas', '6') | ||
=> #<struct Dog name="Bradley", owner="Jonas", age="6"> | ||
1.9.3p392 :003 > d.name | ||
=> "Bradley" | ||
1.9.3p392 :004 > d.age | ||
=> "6" | ||
1.9.3p392 :005 > d.owner | ||
=> "Jonas" | ||
1.9.3p392 :006 > d.name = "Rockey the Dog" | ||
=> "Rockey the Dog" | ||
1.9.3p392 :007 > d.name | ||
=> "Rockey the Dog" | ||
1.9.3p392 :008 > d.age = '100' | ||
=> "100" | ||
1.9.3p392 :009 > d.age | ||
=> "100" | ||
1.9.3p392 :010 > | ||
1.9.3p392 :011 > | ||
1.9.3p392 :012 > d.map{|a|a} | ||
=> ["Rockey the Dog", "Jonas", "100"] | ||
1.9.3p392 :013 > d | ||
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100"> | ||
1.9.3p392 :014 > d.select{|a|a == 7} | ||
=> [] | ||
1.9.3p392 :015 > d.select{|a|a == 7} | ||
=> [] | ||
1.9.3p392 :016 > d.each_pair do |i| | ||
1.9.3p392 :017 > puts i | ||
1.9.3p392 :018?> end | ||
name | ||
owner | ||
age | ||
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100"> | ||
1.9.3p392 :019 > d.each_pair{|k,v| puts k} | ||
name | ||
owner | ||
age | ||
=> #<struct Dog name="Rockey the Dog", owner="Jonas", age="100"> | ||
1.9.3p392 :020 > | ||
|
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good.