I'm having problems setting up wirble on XP machine. when i run IRB i get sth like this:
"foo".capitalize
=> ←[0;31m"←[0;0m←[0;36mFoo←[0;0m←[0;31m"←[0;0m
this occurs only if I call colorize on wirble either in .irbrc or after starting irb. I installed ruby 1.8.6 with the all-in-one installer. Any ideas on how to get colors working?
First install these two gems:
gem install win32console
gem install wirble
Then in your irb console do:
require 'win32console'
include Win32::Console::ANSI
require 'wirble'
Wirble.init
Wirble.colorize
Your input will look corectly:
"foo".capitalize
=> "Foo"
(Foo is in blue on my screen now)
P.S.
If you want irb always to start with these settings just put the above code in the '.irbrc' file in your home directory.
Try this:
http://www.botvector.net/2008/06/colorized-wirble-in-windows-xp.html
(which was the first Google hit for "wirble windows")
Related
I'm trying to write a program with colorized output. I looked at a few, and the gem I found was colorize. I've done some research, but I can't find step-by-step instructions on how to install a gem, require it, and use it. The gem I want is colorize, and I also need to know if there's anything else it requires. All I have is the standard ruby console that comes in the Ruby21 file, and notepad++ to write and save it. I need to know how and where to install it, whether I type something into the terminal or download a file and put it somewhere, and how to require it and its prerequisites(if any) in a file.
You can install the gem using your CLI simply by typing: gem install colorize. You can then utilize the gem by requiring it, so at the top of your .rb file add require 'colorize'. Then just test it out by trying puts "This is blue".colorize(:blue).
Your .rb could look like this for example:
require 'colorize'
puts "This is blue".colorize(:blue)
Per http://guides.rubygems.org/rubygems-basics/, you can install the colorize gem with the following command (in terminal or at command prompt):
gem install colorize
To list local gems, run this command:
gem list
And--by adding require 'colorize' to the top of the respective .rb file--that gem's lib directory will be added to your $LOAD_PATH.
I want to use pry from within irb/debugger, so I can:
invoke step, next, continue, finish inside of pry
still be able to set breakpoints, etc.
What I did is the following:
$ gem install pry
$ gem install debugger
$ gem install debugger-pry
In the code I have inserted require 'debugger'; debugger
Then I start my program with ruby example, the irb promp starts and as described here it should display the pry command on help, but it does not.
ruby-debug help v1.5.0
...
(rdb:1) pry
*** Unknown command: "pry". Try "help".
Any idea how I could check whether it is installed correctly or what am I missing?
I think you need:
require 'debugger/pry'
you could add it to the top of your example.rb file.
awesome_print looks like a pretty nice gem, so I wanted to try it out.
I went to one of my projects and did:
gem install awesome_print
and it says one gem installed, documentation installed, etc.
Then, while I am in that project, I went to my Rails console to try it out, but when I did a require "awesome_print" as their help file says, I get a "cannot load such file".
Has anyone got this to work?
gem install will put the gem code on your computer, but unless the gem's source code files are on your load path, require won't be able to find them. bundle exec looks at the nearest Gemfile.lock and adds the source code for all the gems listed there to your load path. Rails initialization includes getting Bundler to do this for you.
One solution is to add awesome_print to your Gemfile. However, this will cause your application to have awesome_print as a dependency. Alternatively you can manually add the awesome_print library to your load path after starting up the Rails console and then requiring it:
$ rails c
> $LOAD_PATH << path/to/awesome_print-x.x.x/lib
> require 'awesome_print'
> ap {foo: {bar: {baz: :qux}}}
If you're using RVM, the path is likely to be something like:
~/.rvm/rubies/ruby-x.x.x-pxxx#your_gemset_name/gems/awesome_print-x.x.x/lib
Add it to your Gemfile like this:
gem 'awesome_print', :require => 'ap'
I add it to the development group, since that's the only time I need it. The gem doesn't have any other gem dependencies, so I routinely add it to my Gemfile.
Also, add these two lines to your ~/.irbrc file to set ap to be your default pager:
require "awesome_print"
AwesomePrint.irb!
Note that if you use this, however, any projects where awesome_print is not installed in its Gemfile will raise this error when you run rails c:
cannot load such file -- awesome_print
Depending on whatever else you may have in your ~/.irbrc file, this can cause other side effects, such as messing up your prompt. To avoid these, simply add the two lines to the very end of that file.
install it :
$ gem install awesome_print
include it in you GemFile, if you want :
gem 'awesome_print', :require => 'ap'
add this line to the file ~/.irbrc :
require 'awesome_print'
AwesomePrint.irb!
restart your shell!
just a note: I did this and it didnt work right away, probably need to restart the computer... or I just needed to close all shell tabs and open the terminal again!
Install the gem on your machine
gem install awesome_print
Get the path to which it has installed
gem which awesome_print
Add the following configuration to your ~/.irbrc and ~/.pryrc. This will load Awesome Print whenever you fire an IRB or a pry session.
*Remember $LOAD_PATH will hold whatever you got from typing gem which awesome_print
# ~/.irbc and ~/.pryrc
$LOAD_PATH << "~/.asdf/installs/ruby/2.6.3/lib/ruby/gems/2.6.0/gems/awesome_print-1.8.0/lib/"
require "awesome_print"
AwesomePrint.irb!
If you are looking to install it without having it in your Gemfile, this is how to do it:
$ gem install awesome_print
I was running into an issue where it was installing successfully but it not in the right directory.
In that case just put this in your .bashrc, this will set the load path:
export PATH="/home/user/.gem/ruby/2.3.0/bin:$PATH"
PATH="`ruby -e 'puts Gem.user_dir'`/bin:$PATH"
replace 2.3.0 with the version of ruby you are working with.
replace user with your username or if you are using vagrant then replace with vagrant
reload your .bashrc or exit the Terminal to reload changes, then install the gem again.
In my case, I struggled with PATHs and such, while missing something obvious!
# which ruby
/usr/bin/ruby
# ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin17]
# locate bin/ruby
/usr/bin/ruby
/usr/local/Cellar/ruby/2.7.2/bin/ruby
/usr/local/opt/ruby/bin/ruby
# /usr/local/opt/ruby/bin/ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin17]
#
Aha! Version crud. I was running an old ruby. Thanks, Apple!
# sudo mv /usr/bin/ruby /usr/bin/ruby_2.3.7
# sudo ln /usr/local/opt/ruby/bin/ruby /usr/bin/ruby
Solved the problem!
There is probably something I could have told brew to do to fix things, but I was impatient. :-)
Code inspection in the IntelliJ IDEA editor reports a LoadError "no such file to load" on the code
require 'state_machine'
The gem is installed locally. From the command line:
~$ echo $RUBYOPT
rubygems
~$ irb
irb(main):001:0> require 'state_machine'
=> true
So Ruby and Rubygems are playing nicely together. The IDEA Ruby plugin's project settings even lists the gem, so why can't the editor see it?
Ruby version 1.8.7, IntelliJ IDEA 10.5.4.
This gem must be specified in the Gemfile, refer to help.
I'm trying to run a Ruby application that requires Sinatra within Ubuntu 10.10. I'm new to the 3 of these technologies so I understand if this question looks dumb to you.
Yesterday I installed ruby doing...
sudo apt-get install ruby1.9.1-full
And sinatra by doing...
sudo gem install sinatra
This is the code I'm trying to run:
require 'rubygems'
require 'sinatra'
get '/' do
"Hi Alex!"
end
When I do ruby1.9.1 -rubygems app.rb nothing happens (Ruby is properly installed since I tried running apps that don't require sinatra and they work OK).
$ ls
app.rb
$
$ ruby1.9.1 app.rb
$
$ ruby1.9.1 -rubygems app.rb
$
I know it should open Sinatra and tell me which port it is listening to.
I've been looking for help through the web and read several of the threads created within this forum but nothing I've tried has worked out for me.
What could be happening here?
Thanks
There was a similar problem with sinatra 1.0 on ruby 1.9.2. The answer there was to add enable :run to your code.
Have a look at the docs for the :run configuration - if you're going to be deploying to a server you'll want to do something like enable :run if __FILE__ == $0 so that you only start the built-in server during development when you need it.
Strictly speaking your code is correct and should run okay, and in fact it does with ruby 1.8.7 and 1.9.2. The problem seems to be running it with ruby 1.9.1. In general 1.9.1 seems to be fairly outdated and you should probably look to upgrade to 1.9.2 if you can. If Ubuntu doesn't have any packages for 1.9.2 take a look at rvm. (In fact if you're going to be doing ruby development rvm is worth a look anyway).
Update:
I managed to get ruby 1.9.1 compiled to test this, and your code worked ok. Also a bit of googling suggests that the Ubuntu ruby1.9.1 package provides ruby 1.9.2 anyway. So there seems to be something else going on causing :run not to be set when running the file directly, though I don't know what that could be.
Another update:
Looking at the Ubuntu Sinatra package it looks like it's at version 1.0. It could be that your setup is using the Ubuntu
package and ignoring the more recent version installed via rubygems. This could explain what's happening. If so this isn't a "a similar problem" to ruby 1.9 and sinatra 1.0 like I suggested above, it's the same problem!
Yet another update:
A couple of things have occurred to me. You can check what version of Sinatra you're actually using with something like puts Sinatra::VERSION after require 'sinatra'. Also, it looks like there is a gem1.9.1 command that corresponds to ruby1.9.1. It looks like when you installed sinatra with sudo gem install sinatra the latest version got installed into the ruby 1.8 install, and left ruby 1.9 with the Ubuntu packaged Sinatra 1.0. If you haven't switched over to rvm yet, you could try sudo gem1.9.1 install sinatra.