[#366855] what is the correct way to extend native methods? — Maurizio De Santis <desantis.maurizio@...>

Hello!

15 messages 2010/08/01
[#366857] Re: what is the correct way to extend native methods? — James Harrison <oscartheduck@...> 2010/08/01

> return self.select{ |val| val.to_s =~ args[0] } if args.size == 1

[#366864] Re: what is the correct way to extend native methods? — Maurizio De Santis <desantis.maurizio@...> 2010/08/01

James Harrison wrote:

[#366866] Re: what is the correct way to extend native methods? — Brian Candler <b.candler@...> 2010/08/01

Maurizio De Santis wrote:

[#366916] How to remove leading &nbsp; from string — Lucky Nl <lakshmi27.u@...>

Hi

13 messages 2010/08/02

[#366931] Iteration through File.file? misses entries for which File.file?(entry) == true — Kyle Barbour <kyle@...>

Hello everyone,

11 messages 2010/08/02

[#367167] Project name ownership and conflict — Emmanuel Gomez <emmanuel.gomez@...>

I recently had a discussion with a fellow Ruby developer that revealed a

13 messages 2010/08/05

[#367169] Abstracting exception handling — Martin Hansen <mail@...>

Hello,

15 messages 2010/08/05
[#367173] Re: Abstracting exception handling — Brian Candler <b.candler@...> 2010/08/05

> I suspect something is going out of scope and lost?

[#367176] Re: Abstracting exception handling — Martin Hansen <mail@...> 2010/08/05

I was hoping for a setup like this in two files:

[#367177] Re: Abstracting exception handling — Andrew Wagner <wagner.andrew@...> 2010/08/05

What kind of stuff are you doing in my_script.rb? Defining a class? A

[#367179] Re: Abstracting exception handling — Martin Hansen <mail@...> 2010/08/05

Andrew Wagner wrote:

[#367372] Is there any human talkable ruby library? — Sniper Abandon <sathish.salem.1984@...>

Is there any human talk able(like Eliza ) ruby library?

12 messages 2010/08/09

[#367438] Determining whether the running ruby is outdated? — Lars Olsson <lasso@...>

Hi,

14 messages 2010/08/10

[#367540] Ruby is in Grave Danger! — Gregory Brown <gregory.t.brown@...>

Dear Friends,

34 messages 2010/08/11

[#367631] Parsing, BNF, TreeTop, GhostWheel, ... — Philipp Kempgen <lists@...>

Hi,

13 messages 2010/08/12

[#367664] libstdc++ — Pw Ktp <amar.seeam@...>

when trying to install a gem i am getting a 'libstdc++' not installed

24 messages 2010/08/13
[#367666] Re: libstdc++ — Brian Candler <b.candler@...> 2010/08/13

Pw Ktp wrote:

[#367668] Re: libstdc++ — Pw Ktp <amar.seeam@...> 2010/08/13

Brian Candler wrote:

[#367670] Re: libstdc++ — Brian Candler <b.candler@...> 2010/08/13

OK, probably missing headers as Daniel said. Try:

[#367671] Re: libstdc++ — Pw Ktp <amar.seeam@...> 2010/08/13

Brian Candler wrote:

[#367703] Question about learning Ruby effectively — Chan Nguyen <cnguyen@...>

Hi everyone,

12 messages 2010/08/14

[#367781] Unix Philosophy in Ruby Programing — Diego Bernardes <di3go.bernardes@...>

I use Linux about 5 years, but, this year that i started to "use" linux.

22 messages 2010/08/16

[#367833] can i do this in ruby? a simulation process — Bruce Wayner <winshocker@...>

still i don't know how to begin my program on this problem:

56 messages 2010/08/17
[#367834] Re: can i do this in ruby? a simulation process — Jean-Julien Fleck <jeanjulien.fleck@...> 2010/08/17

> Requirements:

[#367837] Re: can i do this in ruby? a simulation process — Bruce Wayner <winshocker@...> 2010/08/17

Jean-Julien Fleck wrote:

[#367839] Re: can i do this in ruby? a simulation process — Jean-Julien Fleck <jeanjulien.fleck@...> 2010/08/17

> Cheers Thanks, anyway i already did writing and other stuff but the only

[#367849] Re: can i do this in ruby? a simulation process — Andrew Wagner <wagner.andrew@...> 2010/08/17

Hmm, I may or may not disagree with you on what the output should be. I

[#367850] Re: can i do this in ruby? a simulation process — Brian Candler <b.candler@...> 2010/08/17

Andrew Wagner wrote:

[#367853] Re: can i do this in ruby? a simulation process — Andrew Wagner <wagner.andrew@...> 2010/08/17

>

[#367858] Re: can i do this in ruby? a simulation process — Bruce Wayner <winshocker@...> 2010/08/17

A superhighway connects one large metropolitan area to another.

[#367862] Re: can i do this in ruby? a simulation process — Andrew Wagner <wagner.andrew@...> 2010/08/17

>

[#367867] Re: can i do this in ruby? a simulation process — Jean-Julien Fleck <jeanjulien.fleck@...> 2010/08/17

> You bring up an interesting point about going

[#367873] Re: can i do this in ruby? a simulation process — Andrew Wagner <wagner.andrew@...> 2010/08/17

Well, it may be interesting, but not in terms of the question originally

[#367911] Re: can i do this in ruby? a simulation process — brabuhr@... 2010/08/17

On Tue, Aug 17, 2010 at 7:34 AM, Andrew Wagner <wagner.andrew@gmail.com> wrote:

[#367922] Re: can i do this in ruby? a simulation process — brabuhr@... 2010/08/17

On Tue, Aug 17, 2010 at 1:19 PM, <brabuhr@gmail.com> wrote:

[#367937] Re: can i do this in ruby? a simulation process — Bruce Wayner <winshocker@...> 2010/08/18

can someone post some code here: I'm only a newbie in ruby :( and

[#367946] Re: can i do this in ruby? a simulation process — Brian Candler <b.candler@...> 2010/08/18

Bruce Wayner wrote:

[#367952] Re: can i do this in ruby? a simulation process — Bruce Wayner <winshocker@...> 2010/08/18

sorry I'm totally suck in ruby here is my code:

[#367965] Re: can i do this in ruby? a simulation process — Brian Candler <b.candler@...> 2010/08/18

> sorry I'm totally suck in ruby here is my code:

[#367967] Re: can i do this in ruby? a simulation process — Brian Candler <b.candler@...> 2010/08/18

>> if $delay1==0;

[#367884] Making File.open work on gzipped files — Martin Hansen <mail@...>

Hello all,

15 messages 2010/08/17
[#367893] Re: Making File.open work on gzipped files — Brian Candler <b.candler@...> 2010/08/17

> This works nicely, but I would like it to work on gzipped files too.

[#367919] Re: Making File.open work on gzipped files — Martin Hansen <mail@...> 2010/08/17

Thanks Brian,

[#367910] Ruby GC question (MRI, JRuby, etc) — Chuck Remes <cremes.devlist@...>

My basic understanding of the garbage collectors in use by the various Ruby runtimes is that they all search for objects from a "root" memory object. If an object cannot be reached from this root, then it is collected.

11 messages 2010/08/17

[#367983] Ruby 1.9.2 is released — "Yuki Sonoda (Yugui)" <yugui@...>

-----BEGIN PGP SIGNED MESSAGE-----

23 messages 2010/08/18
[#368021] Re: [ANN] Ruby 1.9.2 is released — botp <botpena@...> 2010/08/19

2010/8/18 Yuki Sonoda (Yugui) <yugui@yugui.jp>:

[#368023] Re: [ANN] Ruby 1.9.2 is released — botp <botpena@...> 2010/08/19

> weird, since rvm does install it fine.

[#368000] Ruby Code Parsing — Jonathan Bale <webmaster@...>

I have a Perl friend asking me questions about how ruby parses its code.

15 messages 2010/08/18

[#368005] Check existence of object and it's property at the same time — Cory Patterson <coryp@...>

I run into this from time to time and I was wondering if there is a

10 messages 2010/08/18

[#368076] Shoes 3 released — Steve Klabnik <steve@...>

Hey there everyone. We've just released Shoes 3, "Policeman", to

19 messages 2010/08/19

[#368199] A small problem for arrays — Unc88 Unc88 <unc88@...>

I have 2 array. ar_1, ar_2

11 messages 2010/08/21

[#368343] gem list --remote does not work on windows running ruby 1.9.2p0 — botp <botpena@...>

Title says all.

9 messages 2010/08/24

[#368384] ffi-ncurses 0.3.3 — "Sean O'Halpin" <sean.ohalpin@...>

I've just released version 0.3.3 of the ffi-ncurses gem. This fixes

22 messages 2010/08/25
[#368423] Re: ffi-ncurses 0.3.3 — "R.. Kumar 1.9.1 OSX" <sentinel1879@...> 2010/08/26

Sean O'halpin wrote:

[#368500] Re: ffi-ncurses 0.3.3 — "Sean O'Halpin" <sean.ohalpin@...> 2010/08/27

On Thu, Aug 26, 2010 at 11:20 AM, R.. Kumar 1.9.1 OSX

[#368533] Re: ffi-ncurses 0.3.3 — botp <botpena@...> 2010/08/28

On Fri, Aug 27, 2010 at 10:05 PM, Sean O'Halpin <sean.ohalpin@gmail.com> wrote:

[#368538] Re: ffi-ncurses 0.3.3 — Rahul Kumar <sentinel1879@...> 2010/08/28

[#368546] Re: ffi-ncurses 0.3.3 — botp <botpena@...> 2010/08/28

On Sat, Aug 28, 2010 at 2:34 PM, Rahul Kumar <sentinel1879@gmail.com> wrote:

[#368556] Re: ffi-ncurses 0.3.3 — "Sean O'Halpin" <sean.ohalpin@...> 2010/08/28

On Sat, Aug 28, 2010 at 9:47 AM, botp <botpena@gmail.com> wrote:

[#368623] Re: ffi-ncurses 0.3.3 — Rahul Kumar <sentinel1879@...> 2010/08/30

[#368471] how about Array#collect_until — timr <timrandg@...>

I am wondering if anyone has implemented an Array#collect_until method

14 messages 2010/08/27

[#368506] select tr>3 with nokogiri — Pen Ttt <myocean135@...>

13 messages 2010/08/27

[#368690] Namespaces too looooooong — Iain Barnett <iainspeed@...>

Hi,

18 messages 2010/08/31
[#368692] Re: Namespaces too looooooong — Joel VanderWerf <joelvanderwerf@...> 2010/08/31

On 08/30/2010 05:51 PM, Iain Barnett wrote:

[#368694] Re: Namespaces too looooooong — Iain Barnett <iainspeed@...> 2010/08/31

Re: Unix Philosophy in Ruby Programing

From: David Masover <ninja@...>
Date: 2010-08-17 05:16:33 UTC
List: ruby-talk #367826
On Monday, August 16, 2010 07:34:19 am Diego Bernardes wrote:
> Ruby was build to help manage linux
> systems, rigth?

I don't think so. Perl, maybe, but Wikipedia has this quote from Matz:

"I wanted a scripting language that was more powerful than Perl, and more 
object-oriented than Python. That's why I decided to design my own language."

> Why build a gem/program to send mail if you can send with sendmail?

mberg@damnation.org pretty much nailed this one -- sendmail isn't a 
particularly good interface for sending mail. Maybe it's a flaw in Ruby, but 
it really is more difficult to invoke an external command (with appropriate 
arguments), communicate with it, and capture the result than it is to use 
something more native to Ruby.

I haven't sent email in awhile, but let's use a more direct example: grabbing 
the contents of a URL. I could do it with wget:

system('wget', some_url) || raise "wget exited with error code #{$?}!"
contents = File.read '/wherever/wget/put/the/file'

Or I could do it with the 'curl' binary (or a more complex wget command):

contents = `curl #{some_url}`

...but then, how do I detect errors? What if some_url needs to be shell-
escaped? Hmm. Maybe I could do popen, but that's more complicated...

Or I could do this in pure Ruby:

require 'open-uri'
contents = open(some_url) {|x| x.read}

To me, this is both more natively Ruby, and more in keeping with the Unix 
philosophy -- open-uri is a small library that does one job, and does it well. 
I then don't have to repeat myself with tons of error-handling crap all over 
the place, as I do with system, or risk silent errors, as my above backticks 
example might do -- I can assume open-uri will return an error if something 
goes wrong.

If I need more control, I can always use Net::HTTP, or one of the many other 
libraries available. Aside from having comprehensive documentation, it's, 
again, more native. Here's an example from the standard library docs:

    res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
                              {'q'=>'ruby', 'max'=>'50'})

And here's that same example with Curl:

curl -F q=ruby -F max=50 http://www.example.com/search.cgi

Here it is calling Curl from Ruby:

uri = 'http://www.example.com/search.cgi'
q = 'ruby'
max = 50
res = `curl #{uri} -F q=#{q} -F max=#{max}`

But what if I want to generate those query options on the fly, from a hash? 
It's trivial to do with Net::HTTP.post_form, but with curl?

uri = 'http://www.example.com/search.cgi'
options = {'q' => 'ruby', 'max' => 50}
options_string = options.each_pair.map{|k,v| "-F #{k}=#{v}"}.join(' ')
res = `curl #{uri} #{options_string}`

And the best part? In each of the two examples above, I again may have to 
escape things for the shell, if I don't know where those options are coming 
from. Curl is sane enough that I probably don't have to escape them for Curl 
itself, at least. And I've again done no error checking -- I'm just getting a 
giant string back.

To be fair, I didn't do any error checking in my earlier example from 
Net::HTTP, but that's easy to do:

    res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
                              {'q'=>'ruby', 'max'=>'50'})

    res_value = res.value   #throws exception unless it was successful

And if there is an error, I can tell exactly what kind of error:

    res.kind_of? Net::HTTPNotFound   # true
    res.code                         # "404"
    res.body                         # contents of the 404 page

With Curl, I have to pass some extra commandline options to ensure I get that 
information, probably specifying a custom output format so I can get the error 
code, and then I have to parse that output format. Yuck -- I may as well parse 
raw HTTP.


I didn't really answer your question about Sendmail, then, but I suspect the 
answer would be similar to the answer to the same question about Curl -- maybe 
more so. The Mail gem, for instance, handles things like file attachments -- I 
don't think the sendmail interface does that, at least not directly, so you'd 
still need something like Mail to wrap Sendmail if you wanted to use it 
sanely.


Now, you might well ask why we don't just wrap these existing binaries in a 
gem. It's not clear that there would be a huge benefit, though. Most of the 
time, properly-engineered Unix binaries also have C libraries, and it's 
probably easier and cleaner to write a Ruby binding for a C library than to 
write a Ruby wrapper around a Unix executable -- for one, you don't have to 
deal with escaping commandline arguments or passing text back and forth 
through a pipe just to communicate, you've got an actual API to work with.

There are a number of side benefits to the current approach. For one, it's 
ridiculously portable -- the JRuby guys have Rails running on AppEngine and 
IRB running on Android, in environments which wouldn't make it easy (if it 
were allowed at all) to use C extensions or binaries. I can write my HTML 
parsing once, using Nokogiri, and it will use libxml on MRI and (I think) the 
standard Java XML libraries on JRuby.

And, even more fringe benefits -- not forking off a separate process per 
request is likely faster, and passing around Ruby data structures, or ever 
converting from Ruby strings to C strings, seems cheaper than converting 
everything to giant blobs of text, squeezing it through a pipe, and parsing it 
in another process.

But you'll notice, I call these "fringe benefits", and I use a lot of weasel 
words. For all I know, separate processes might be faster. I do use RESTful 
services as components of a larger app, the Unix philosophy taken to an 
extreme -- this could be one physical _server_ that does one job and does it 
well.


I think it just comes down to this: Ruby semantics are richer than Unix 
semantics, and where Unix makes sense, HTTP might make even more sense.

I'm not saying "system considered harmful" -- far from it, I'd be the first to 
call Unix commands when appropriate (xdg-open, for example), or even to write 
a quick shell script in sh or bash instead of trying to learn something like 
Rush.


> Why build process monitor if you can use monit?

Well, or God, or any number of other things. I think the answer to this one 
is, choice is good, and this isn't quite a solved problem yet.

In This Thread