alexch / learn_ruby Goto Github PK
View Code? Open in Web Editor NEWa basic ruby class generated from test-first-teaching
Home Page: http://testfirst.org
a basic ruby class generated from test-first-teaching
Home Page: http://testfirst.org
https://github.com/alexch/learn_ruby/tree/master/04_pig_latin
All right, 6-8 hours over 3 days on this one.... could use a clue...
I feel I'm very close. The idea is to split the string into words, and then split the words into letters. Find the first vowel in each letter array - with a special case if inculde?("q")
repl.it appears to give me the correct return, but rspec does not.
Example from rspec:
expected: "appleay"
got: "["a", "p", "p", "l", "e"][]ay" (using ==)
Any easy way to turn "a", "p"\ into "ap"? array.join and array.flatten don't do it.
My code - which I'm pretty proud of after all this time:
def translate(string)
string.downcase!
split_array = string.split(" ")
split_array_final_composite = []
split_array_letter_end = []
split_array.each do |word|
if word.include?("q")
#here I'm trying to get an index for the first vowel. Has to be a better way, but it works!
string_copy = word.clone
string_copy[/[aeio]/] = ''
string_index = string_copy.index("")
split_array_letter = word.split("")
split_array_letter_end = split_array_letter.shift(string_index)
split_array_final_composite<<"#{split_array_letter}#{split_array_letter_end}ay"
else
#here I'm trying to get an index for the first vowel. Has to be a better way, but it works!
string_copy = word.clone
string_copy[/[aeiou]/] = '*'
string_index = string_copy.index("*")
split_array_letter = word.split("")
split_array_letter_end = split_array_letter.shift(string_index)
split_array_final_composite<<"#{split_array_letter}#{split_array_letter_end}ay"
end
end
split_array_final_composite.flatten #this is un-necessary
return split_array_final_composite.join(" ")
end
repl.it returns:
=> "ethay ickquay edray oxfay umpsjay overay ethay azylay ogday"
** It just now occurs to me that perhaps I don't have to split into letters any more, since now I've found a different way to find that vowel index, which was the original purpose of splitting into letters..... I'll try again without that step and see what happens.....
** No, that's right, I did need to split into letters because "shift" works for entire array elements, not for each contstituent part of the element.... still stumped....
https://github.com/alexch/learn_ruby/tree/master/03_simon_says
This is a clear user error, but I can't find a different method or think of a different way.
In the "repeat" method, I'm supposed to be able to take any text and repeat it X number of times. The "times" method seemed the best way, but "times" returns the integer, not the printed text. I can't get past this exercise right now!
def repeat(input, x=2)
x.times {print "#{input} "}
end
http://www.wiki.devchix.com/index.php?title=Workshop_Installation_Notes_Rails_3
is no longer accessible. i looked through devchix.com but couldnt find any ruby install help.
Using rspec 3 causes the first run of rake to fail as it's unable to find the required rspec version (~2).
See also (first answere here)[https://stackoverflow.com/questions/25107583/rake-aborted-gemloaderror-could-not-find-rspec-x-but-did-find-y].
hello,
While working on the dictionary exercise, I was running into some problems. For a check, I decided to run your solution, but your solution was failing the 2nd test. Do I need some special installation to run "Dictionary" that is different from the previous exercises?
Thanks
I have Ruby 1.9.3 installed. When I tried doing the exercises, I kept getting this error:
/Users/stevenjli/Documents/App Academy/learn_ruby-master/00_hello/hello_spec.rb:116:in `require': cannot load such file
I asked around StackExchange, where the posters suggested that "require" might be the issue. Namely, because I'm using Ruby 1.9.3, the "require" needs to be changed to "require_relative." They were right. I went through every spec.rb file and changed "require" to "require_relative" and this got things working.
https://github.com/alexch/learn_ruby/tree/master/00_hello
This is for everyone's benefit:
I think this is partially because I'm running Ruby 2.0.0, not 1.8.7
When I try "rspec hello_spec.rb" from the Terminal, I get that it can't load the "hello" file, with a listing of directories that it tried to load it from.
I did not define those directories, nor do I know if I can change them.
However, a little research shows me that I can use the "require_relative" method instead of simply "require." Then, if I put "hello.rb" in the same folder as "hello_spec.rb", I can run the test and everything works out.
That took me an hour, so I hope this post saves somebody some time!
"resolves operator precedence unambiguously" test tries doing two consecutive calculations without resetting the calculator. Basically, it is testing whether:
2+3_((1 + 2) * 3)==1+(2_3)
A fix would to be to require a method that resets the calculator and use that between the tests, or create a new instance of RPNCalculator before the test.
Relevant Code in rpn_calculator_spec.rb:
it "resolves operator precedence unambiguously" do
#1 2 + 3 * => (1 + 2) * 3
calculator.push(1)
calculator.push(2)
calculator.plus
calculator.push(3)
calculator.times
calculator.value.should == (1+2)*3
####
#Tom Conrad: Error here. Calculator has
#to be reset.
####
#1 2 3 * + => 1 + (2 * 3)
calculator.push(1)
calculator.push(2)
calculator.push(3)
calculator.times
calculator.plus
calculator.value.should == 1+(2*3)
end
In the simon_says_spec.rb you use 'little words'. Could you please explain what you mean there?
The solution is found here: http://stackoverflow.com/questions/35893584/nomethoderror-undefined-method-last-comment-after-upgrading-to-rake-11
Here are very detailed directions in the case that more information is needed or the link doesn't work:
1] Go to the project's folder and open Gemfile (not lock) in your text editor
2] Comment out (Add a #
before the text) or delete the line stating gem rake
3] Add the line gem 'rake', '< 11.0'
4] Open your terminal or command line with the current directory being inside the project's folder
5] Run bundle install
6] Run grep rake Gemfile.lock
Now when you cd into a specific excercise and run rake
, it should work (you'll receive output from a failed test)
Good Evening,
I have been unable to run the tests and I have no clue what is wrong. I am encountering an issue in the terminal after running the 'rake' command per the instructions in the index.html file. This is the message that I receive, any suggestions or advice would be greatly appreciated. Thank you.
$ rake
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in eval' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in
$ rake --trace
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:632:in raw_load_rakefile' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:94:in
block in load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in standard_exception_handling' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:93:in
load_rakefile'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:77:in block in run' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:165:in
standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/lib/rake/application.rb:75:in run' /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rake-10.1.0/bin/rake:33:in
<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake:19:in load' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/rake:19:in
eval' /usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in
'A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.