setting up Ruby Koans - ruby

This question is probably pretty stupid/n00bish/inappropriate/localised/sparkly cake, so downvote all you like as long as I get the answer, as I wish very much to be able to go through the koans. :)
I am trying to get this to work. (GitHub is here) I've downloaded and extracted it, and the folder is in my Documents directory (I renamed it ruby_koans from the default name). I've been messing around with this all day and can't get it to run in Konsole. :/
I use
cd /home/sophia/Documents
to move to the directory Documents, which contains the ruby_koans file.
I have no idea what to do after that, as Rake seems to be broken, and I probably installed Autotest incorrectly :S
And, before posting here, I already asked #ruby and #kubuntu on freenode. ._.

Try to install the koans from http://rubykoans.com/
They have detailed installation instructions and a troubleshooting section.
If for some reason things still don't work properly, then you should seek help from a real-life programmer friend who has done this before :)
old answer:
Please, try to run the "path_to_enlightenment.rb" file inside the "koans" directory.
cd koans
ruby path_to_enlightenment.rb
That doesn't use rake. If that doesn't work, then your ruby installation may be broken.
The first line of the "path_to_enlightenment" is:
LOAD_PATH << File.dirname(__FILE__).
This makes "require" look for files in the current directory.
Perhaps File.dirname(__FILE__) does not return the proper value(for some reason).
Try and replace File.dirname(__FILE__) with the absolute path of the directory in which the koans are. I.e. "/home/MYUSERNAME/ruby_koans/koans/".
If I had to guess, I'd say the problem is that the "Documents" folder has an uppercase D in it. You can also try and move the project somewhere else.

git clone https://github.com/renemendoza/ruby_koans.git
cd ruby_koans/koans
autotest
If autotest is not already installed, you'll need to do gem install autotest.
Open each script and fill in the correct answers as prompted. When you save changes autotest should rerun and show you the next failing one.

For those that got here after downloading the Koans from the renmendoza or neall versions of the koans, you'll want to get them from https://github.com/edgecase/ruby_koans now. Be sure to run rake gen before starting.

Related

RSpec basics: bin/rspec --format doc

I've installed RSpec on a win7 lappy and am following along the http://rspec.info/ homepage tutorial to make sure everything works. If I am reading their demo correctly bin/rspec --format doc should run the specification test file.
Instead, I get a system prompt for a text editor... ? I am confused.
Any explanation of what is going on or guidance about how to get my RSPEC configuration working in accordance to the makers homepage would be great.
FWIW Ruby 2.2.5p319, Bundler version 1.13.1 and gem -v tells me 2.6.7 (originally I had 2.4 but that is broken on windows, so I upgraded according to http://guides.rubygems.org/ssl-certificate-update/) Also, I have basic RSpec functionality and have completed the tutorial here: https://www.tutorialspoint.com/rspec/rspec_writing_specs.htm
Ah, I figured out what I need to do... I just need to explicitly call ruby:
ruby bin/rspec --format doc
...and the test gets run - YaY!
Per #JörgWMittag, I confirmed my Environment Variable Path to make sure ruby.exe was in there (C:\Ruby22\bin;).
Then looking at my Program Defaults, I thought that maybe I could tell win7 to associate any file named "rspec" with ruby.exe per https://support.microsoft.com/en-us/help/18539/windows-7-change-default-programs ...but I couldn't actually add file type "extensions" or "protocols" - I could only change the association of existing ones, but .rb and .rbw were in there... Maybe there is a way to do this manually, but I am not a windows expert.
Thinking on all this it occurred to me that I just needed to explicitly tell ruby to ingest the command... Heh.
I apologize if this is off-topic.

How to require ruby gem from a specific location?

I am new to ruby, and is trying to write a git hook in ruby. I want to use the rugged gem in my script. The gem is already available in /opt/gitlab/embedded/service/gem/ruby/2.1.0/ as part of GitLab installation (Files List). How can I require that gem in my script?
I have tried $LOAD_PATH.unshift "/opt/gitlab/embedded/service/gem/ruby/2.1.0/" and then require "rugged", as mentioned in another stackoverflow answer, but it did not work.
Look carefully at how $LOAD_PATH is configured for each gem after you include it. Normally it's the full path to where the base gemname.rb is located, like in your case where rugged.rb is.
The way the $LOAD_PATH works is it scans through that list looking for rugged.rb and if it doesn't find it, moves on to the next possible location. You're specifying a directory which doesn't have that, so find the right path and fill that in, and you should be good.

Malformed version number string

I recently installed a gem that was inappropriately named. My installation thinks the the version number is "Epub". The gem is called Simple Epub Creator-0.0.0.gem. I already know what I did wrong (used spaces) but now I need to fix it.
Whenever I run gem with any argument, including uninstall, I get this:
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:200:in `initialize': Malformed version number string Epub (ArgumentError)gem
Followed by a stack trace as long as my arm. Is there an elegant fix to this problem, or is it better to just take the "sledgehammer" approach and nuke the installation, followed by a clean install of ruby and all of the gems I use?
I had a similar issue when I inadvertently did a rake:install on a gem I was building that didn't yet have a version number assigned to it. Running gem, bundle, or rake with any commands resulted in the same error about a malformed version number.
What worked for me was manually deleting all instances of the offending gem in the .rvm folder. In my case, I had a gem named dogecoin- that was missing a version suffix. So cding into my .rvm directory and running find . -path \*doge\* -delete got me back into a functioning state.
My hunch is that version.rb goes through all the gems that you have installed, one of which is your misnamed epub creator.
Maybe you could take a look at the line 200 in the file C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/version.rb, see where it's trying to load the misnamed gem, find it and delete it?
I couldn't find the files in the reference path, or some of the other suggested paths in this post. Some thing that helped me was to first comment out the error be raised in the version.rb file on line 201. Then use the GEM PATH directory using $ gem env to find the path that had references to the gem. Make sure to remove everything from the doc, cache, and specifications folders. This finally solved my issue.
I had this same problem today. I was using Ruby installed through homebrew. I found remnants of the bad gem in the following folders. Deleting the references from these two folders seems to have fixed the problem:
/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/doc/
/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/specifications/

Finding short path to Foundation

Can someone explain why the short path in my config.rb file isn't compiling:
require 'zurb-foundation' # it fails
But when I specify the full path it does:
require "/Users/lukashillebrand/.rvm/gems/ruby-1.9.3-p327/gems/zurb-foundation-4.2.2/lib/zurb-foundation.rb";
I'm using CodeKit to compile and Foundation 4
The reason is that CodeKit is apparently using the system ruby, and so the relative path is looking there. Your full path is pointing to an rvm version, which is installed elsewhere.
The quick fix is temporarily switch rvm to the system ruby & gemset, and install zurb-foundation there:
$ rvm system
$ sudo gem install zurb-foundation
I do not know zurb, just Ruby as a language/platform, and I think that if that first 'require' throws, then most probably some paths are not set up properly in your server environment.
Is Zurb distributed as a gem? Are other gems found well and are require'able by your code? If not, or if you don't know, try adding
require "rubygems"
as the very first line of your code (well, after some initial shebang and other comments). It should normally be invoked by the framework, somewhere before your file, but as I already said, I don't know Zurb. Maybe it simply does not do that for performance reasons.
Also, run some simple file in the same environment and inspect the $: variable, it should show you the paths that are searched for modules. If in very deadline'y times, you can even temporarily push a new path to it (just replace the '.' with your target path), but it'd be best left as a last resort. Your zurb module seems to sit in Gems, so it should be found automatically.

Is it possible Ruby installation by copying the ruby folder?

This is a very silly question...
I have a doubt regarding the ruby installation. Will the ruby be installed in a windows server if we copy the Ruby187 folder from another server and add that in the PATH of the environment variable?
Or Do we need to install the Ruby from the installer always, in order to install it ?
Thanks in advance
I actually did something similar to this yesterday at work. A fellow co-worker, who does not have Ruby installed on their system, needs the ability to run my scripts while I am on vacation. So, I copied the entire Ruby folder from my C: to a shared network drive.
You will not only have to add the path to the Ruby folder to your PATH variable but you also may want to associate the Ruby extension .rb with Ruby. Not needed but just a thought.
One issue I ran into was here at work we don't have permission to alter our PATH variable manually. So, in order for my co-worker to launch the scripts I needed ran, I wrote a small C++ app that merely run a command line call to the Ruby interpreter and then to the script to run.
So, in short, yes, it is possible. =)
EDIT: In regards to why you would add the path to the Ruby installation to the PATH variable, it is so you can call Ruby from the command line with simply C:\>ruby some_script.rb. Without that added to your PATH, you'd need to type the entire path every time like C:\>C:\ruby192\bin\ruby some_script.rb. However, you'd still need to type "ruby" first.
In regards to the association of ".rb" files to the Ruby Interpreter, it is an option while installing Ruby on Windows using the installer provided at ruby-lang.org. With that, you would not need to type "ruby" before the script name on the command line. C:\>some_script.rb would work. I don't know exactly how to do this with a network version of Ruby but one way might be to right-click on a ".rb" file, choose "Open with..." and locate the Ruby.exe file in \ruby192\bin\ruby.exe.
I hope that explains what you were asking about in the comments.

Resources