Am I wrong in the understanding that the ruby gems that add
functionality to ruby do it by wrapping c programs with ruby syntax
somehow. And if this is the case is there much of a difference between
using a gem like RMagick and just doing a system call:
system ‘rmagick comand’
On Tue, Jul 19, 2011 at 12:17 AM, Tyrel R. [email protected]
wrote:
Am I wrong in the understanding that the ruby gems that add
functionality to ruby do it by wrapping c programs with ruby syntax
somehow.
Yes and no. RubyGems can be used to distribute gems that include
C/++/Java/.NET extensions (Java and .NET for JRuby an IronRuby,
respectively), but they don’t have to.
There’s plenty of gems that are pure Ruby libraries, as well (I’m
quite sure that the vast majority of libraries meets that, actually).
And if this is the case is there much of a difference between
using a gem like RMagick and just doing a system call:
system ‘rmagick comand’
The difference is like using a single LEGO brick (farming out to the
command line), or a couple of them to build something new (using the
pg gem to access a PostgreSQL database, use the RMagick gem to
generate a map with GPS data, and the Prawn gem to write a PDF).
Sure, you can do all that from a command line, but that can be costly,
brittle, or both.
–
Phillip G.
phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz
It depends on what your needs are. You can also embed ruby( and any
language) inside a shell script. The key to understanding which tool
to use is to identify the right tool for the right job.
If I was to use say ‘convert’ from ImageMagick and had a legacy
“WhoTheFooCaresWhatLangIt’sIn” script I may consider calling it with
IO:popen or one of it’s cousins or if it’s trivial script use the gem
and build the tool in ruby.
For simple things like sifting info from the environment backticks and
env may be one way to go.
system() might be a place to call the users editor from inside the
program i.e:
system( “#{ENV[‘EDITOR’]} /tmp/foobar”)
Hope some of this info helps.
~Stu
On Tue, Jul 19, 2011 at 07:17:52AM +0900, Tyrel R. wrote:
Am I wrong in the understanding that the ruby gems that add
functionality to ruby do it by wrapping c programs with ruby syntax
somehow. And if this is the case is there much of a difference between
using a gem like RMagick and just doing a system call:
system ‘rmagick comand’
Ruby gems aren’t about extending Ruby, per se. Instead, they are a way
for packaging and distributing libraries and extensions that allowing
for retrieving specific versions and their dependencies.
For example, if you write an app that requires the Ruby library
“farkle”, then you can use the gem repository to retrieve the “official”
copy of farkle easily, install it in your local system and make use of
it. And those who use your application can also easily retrieve the
same gem, install it and have it available while using your app. All
without you having to worry about packaging up the “farkle” code and
getting it to the user.
And if you need a specific version of “farkle”, gems allow you to
specify that version as well. So if you depend on an older version, you
can retrieve it in the same way you would the latest copy.
Hope that helps.