I am interested in creating a command line application with ruby that would require moderately complex interaction with the user. I would like to use ncurses for this.
What is the best gem for working with ruby and ncurses, or should I be using stdlib utilities in ruby?
Ruby includes bindings for the curses library. Despite what the name implies, it will use ncurses if possible.
Third party libraries often provide abstractions on top of either Ruby's curses or their own bindings. For example, ncursesw also wraps the panel, menu and form extensions. When I worked with Ruby's curses, I created my own Window class with proper border support.
If the basic methods are sufficient, I don't see any reason to add a dependency to your project. However, if you want to do fancy things more easily, you should use a library that provides support for what you need.
I have found ncursesw on this Rubygems seach. Seems to be a good gem to start with.
This one appears to have the best readme https://github.com/seanohalpin/ffi-ncurses
Related
RubyMotion does not support
require
in code (only in RakeFile).
Is there a way to use useful classes built into Ruby but not into RubyMotion ? For instance, I'd like to be able to do a
name=Pathname.new("/path/to/some/file").basename
rather than look for Cocoa equivalent
Pathname is one of those pieces of the Ruby Standard Library that are not available in RubyMotion.
You can try with MotionBundler, but I personally haven't been very lucky with that.
I'd suggest to use the Cocoa equivalent.
Something like:
name = "/path/to/some/file".lastPathComponent
Not that bad, anyway.
Does an (experimental) class browser exist for Ruby?
I am talking about a class browser/editor combination similar to that of most Smalltalk implementations (i.e. focused on [runtime] classes/objects instead of .rb files)
P.S.: it looks like pry is already able to do a lot of the things that would be needed by a smalltalk style class browser? https://speakerdeck.com/u/rahult/p/pry-an-irb-alternative-on-steroids
P.S.2: Looks like the Seaside Smalltalk framework has a web browser based class browser
P.S.3: MagLev/Webtools is the closest I have found yet:
P.S.4: Apparently http://tibleiz.net/code-browser/index.html has Ruby support and is able to present a Smalltalk like class browser:
Check out the maglev/webtools project on github, as well as the rubymirrors gem. It already provides a class browser and workspace for multiple Ruby implementations, and a graphical debugger works on MagLev as well (not so much on MRI).
If you want to build one, the easiest would be to use MOOSE and build the browser with Glamour, on top of a Ruby parser written in PetitParser. Then you could use Pharo as your Ruby IDE.
You can have a look at the Maglev Database Explorer [1, 2] as well.
[1] Video: http://www.youtube.com/watch?v=27mS1BNP7wQ
[2] Gem: https://github.com/matthias-springer/maglev-database-explorer-gem
There is. It is called Reflexive. https://github.com/dolzenko/reflexive
(I've never taken the time to try it though, so I am curious about other experiences with it.)
I have no experience with it (and it is old), but may be rbbr still works.
I want to build a console-based application with Ruby. I quick googled and found all of these below libraries. Please someone suggest me which one should I use. Thank you.
OptionParser (http://ruby-doc.org/stdlib-1.9.3/libdoc/optparse/rdoc/OptionParser.html)
Thor (https://github.com/wycats/thor)
Rubikon (http://koraktor.de/rubikon/)
Trollop (http://trollop.rubyforge.org/)
Clamp (https://github.com/mdub/clamp)
Choice (http://choice.rubyforge.org/)
Methadone (https://github.com/davetron5000/methadone)
GLI (https://github.com/davetron5000/gli)
Commander (http://rdoc.info/github/visionmedia/commander/master/frames)
Main (https://github.com/ahoward/main)
CLAP (https://github.com/soveran/clap)
Optiflag (http://optiflag.rubyforge.org/)
Hirb (http://tagaholic.me/hirb/)
Boson (http://tagaholic.me/2009/10/14/boson-command-your-ruby-universe.html)
Ruby Toolbox is a website for comparing different gems. You may want to use it to evaluate which gems are reasonably popular.
You may find Really Cheap Command-Line Option Parsing in Ruby useful as well.
According to this post, requiring rubygems is an antipattern.
require 'rubygems'
The argument seems to boil down to this:
When I use your library, deploy your
app, or run your tests I may not want
to use rubygems. When you require
'rubygems' in your code, you remove my
ability to make that decision. I
cannot unrequire rubygems, but you can
not require it in the first place.
But couldn't the same argument be made about any Ruby library that you 'require' when you create and share a library of code with other people?
If you look at the comments, you will see the author say this
The point I was not trying to make is
that rubygems is bad or that people
shouldn’t use it. I use rubygems and
think it’s a critical piece of Ruby’s
success – I just don’t have the line
“require 'rubygems'” anywhere in my
library’s source code because it’s not
necessary or convenient and makes it
hard / impossible for other
environments (like bundler, rip, GAE,
debian, hand rolled, etc) to use the
library without rubygems, which is
often important.
I actually didn't really agree with him before I read it, now I do
The main problem with requiring rubygems is that it will cause an error on systems that do not have rubygems installed even if they do have the library that you actually want to require.
Some people work around that by rescuing LoadError when requiring rubygems, but that's kind of ugly.
Rubygems isn't essential to the application, it's just a convenient way of supplying a library. By contrast, the other libraries used are essential to the application.
I can't find many docs on this. How do I package a gem such that the C extension is compiled when the gem is installed?
In particular I want to do this:
on Linux and MacOSX i would like compile the C extension on gem install
on Windows I would like to simply install a precompiled .so
any help on this, in particular example source, would be very useful :)
Luis Lavena has created rake-compiler just for this purpose.
Homepage / GitHub
GitHub Wiki
However, are you sure that you need a C extension? The thing about C extensions is that every Ruby implementation has their own C extension API (and non-C based ones like XRuby, JRuby, Ruby.NET, IronRuby, HotRuby, MagLev, Red Sun don't have one at all), which means that your C extension will only work on one implementation. And, since MRI only implements Ruby 1.8 and YARV only implements Ruby 1.9, and we are currently in a transition phase between 1.8 and 1.9, chances are that a lot of people will use at least two different implementations. (I personally use 5: MRI, YARV, JRuby, IronRuby and Rubinius.)
Maybe you are better off using Ruby-FFI. Ruby-FFI is an FFI (Foreign Function Interface) for Ruby (duh), which allows you to bind to and map C libraries in pure Ruby in a manner that is portable across Ruby implementations. The FFI API was first developed by Evan Phoenix as the native extension API for Rubinius, it was then adopted by Charles Oliver Nutter (and implemented by Wayne Meissner) for JRuby. Wayne then also wrote the Ruby-FFI gem, which contains C extensions for MRI and YARV. Laurent Sansonetti implemented Ruby-FFI for MacRuby, Marc-André Cournoyer's tinyrb also supports FFI (again written by Wayne Meissner) and the MagLev developers are also working on it. Which means that if you can make your library work with FFI as opposed to a C extension, you will automatically support 6 Ruby implementations instead of just one.
The only reason to use a C extension as opposed to an FFI extension would be, if you really do want some implementation specific behavior. One example of this would be the ParseTree gem, which reaches deep into the intestines of MRI and rips out the in-memory representation of the parse tree.
Last but not least, take a look at the Nice-FFI project by John Croisant, which aims to make using Ruby-FFI even nicer.
I have a github repo that I maintain just for my own reference and these things have helped me.
Ruby_C_extensions
It may help to look around on github to find some good examples of gems already written just for your study but go ahead and clone them and see if you can build them on your system. If they were put together right they should build just fine.
Please note that you do need some build tools in any platform you're using. Here is a video that I just watched that tells you what you need for Linux.
Python Programming Environment Setup
Now I know that that it says Python, he does show you how to install the build tools packages.
I use DevKit for Windows and it works for me. With anything the installation of the tools is the most important.
I also have used rake-compiler and hoe to set up the folder structure. So it looks like we have to lean some gardening by getting a rake and a hoe. :-D