how do I contribute to Ruby?

G

Giles Bowkett

check this out, this is the whiniest change ever, but what I want is
this to work:

irb(main):001:0> "".is_a? String
=> true
irb(main):002:0> [].is_an? Array
NoMethodError: undefined method `is_an?' for []:Array
from (irb):2


I just HATE writing "is_a? Array" because it's grammatically incorrect.

I realize this is incredibly silly and anal, but the thing is, all you
have to do is one simple alias command and you're good to go.

so -- how do I contribute to Ruby itself?
 
G

Gabriele Marrone

I just HATE writing "is_a? Array" because it's grammatically
incorrect.

What about String#include? isntead of includes? :p
I realize this is incredibly silly and anal, but the thing is, all you
have to do is one simple alias command and you're good to go.

so -- how do I contribute to Ruby itself?

Do you mean how to add functionalities to core classes?

class Object
alias :is_an? :is_a?
end

"is_an?" is now an alias to "is_a?"
 
G

Giles Bowkett

No, I mean where to submit that change, having made it. Although I
suppose if you go ahead and submit it, you get all the glory (Ruby
contributor! wow! that must look good on a resume).

I mean it is a pretty obvious change.

String#include? doesn't bother me for some reason. I don't know why.
 
E

El Gato

Giles said:
check this out, this is the whiniest change ever, but what I want is
this to work:

irb(main):001:0> "".is_a? String
=> true
irb(main):002:0> [].is_an? Array
NoMethodError: undefined method `is_an?' for []:Array
from (irb):2


I just HATE writing "is_a? Array" because it's grammatically incorrect.

I realize this is incredibly silly and anal, but the thing is, all you
have to do is one simple alias command and you're good to go.

so -- how do I contribute to Ruby itself?

Well, unlike a lot of languages, in Ruby you can modify all sorts of
built-ins. I don't personally believe that a case such as this
warrants it though, and often in Ruby it's better to use respond_to?
(duck typing) depending on the situation of course.

class Array
def is_an?(klass)
return is_a?(klass)
end
end

[].is_an? Array #=> true
 
D

David Vallner

--------------enigE110ED84E92F29477D1CAA33
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Giles said:
No, I mean where to submit that change, having made it. Although I
suppose if you go ahead and submit it, you get all the glory (Ruby
contributor! wow! that must look good on a resume).
=20

Dear LORD in heavens.

Makes me wonder if HR people do investigate whether "contributor"
actually means "commit whore".

On a less flamey note, that change is just too silly to be in the core
library, I don't need -yet- another "foo is a synonym for bar" in the
documentation.

David Vallner


--------------enigE110ED84E92F29477D1CAA33
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFZY+Dy6MhrS8astoRAhlsAJ96EHkVfTMoOH+3b8a4ydsLM0gB2gCaA98x
/cT7OwJv+yjfPidjKHK4SyU=
=jKOE
-----END PGP SIGNATURE-----

--------------enigE110ED84E92F29477D1CAA33--
 
D

dblack

Hi --

Giles said:
check this out, this is the whiniest change ever, but what I want is
this to work:

irb(main):001:0> "".is_a? String
=> true
irb(main):002:0> [].is_an? Array
NoMethodError: undefined method `is_an?' for []:Array
from (irb):2


I just HATE writing "is_a? Array" because it's grammatically incorrect.

I realize this is incredibly silly and anal, but the thing is, all you
have to do is one simple alias command and you're good to go.

so -- how do I contribute to Ruby itself?

Well, unlike a lot of languages, in Ruby you can modify all sorts of
built-ins. I don't personally believe that a case such as this
warrants it though, and often in Ruby it's better to use respond_to?
(duck typing) depending on the situation of course.

Or just duck typing, without respond_to?; i.e., just send messages to
objects based on the semantics of the message.


David

--
David A. Black | (e-mail address removed)
Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org
 
G

Giles Bowkett

Dear LORD in heavens.

Makes me wonder if HR people do investigate whether "contributor"
actually means "commit whore".

The type of companies that hire through HR people, no, they don't
check. Maybe Google's HR does, but even there I doubt it. Hiring
through HR people is a guarantee for questions like, "We need five
years of Rails experience, do you have that?"
On a less flamey note, that change is just too silly to be in the core
library, I don't need -yet- another "foo is a synonym for bar" in the
documentation.

I did say it was the whiniest change ever. It might be too silly for
the core library, hell, it's probably too silly for its shirt -- so
silly it hurts -- but using "a" where I should use "an" just sets off
my inner compulsive librarian.
 
G

Giles Bowkett

Well, unlike a lot of languages, in Ruby you can modify all sorts of
built-ins. I don't personally believe that a case such as this
warrants it though, and often in Ruby it's better to use respond_to?
(duck typing) depending on the situation of course.

class Array
def is_an?(klass)
return is_a?(klass)
end
end

[].is_an? Array #=> true

Just as an aside, to implement this, I would much rather monkeypatch
Object than Array. Otherwise it just happens again the next time I
have a class which begins with a vowel.
 
H

Hugh Sasse

class Array
def is_an?(klass)
return is_a?(klass)
end
end

[].is_an? Array #=> true

Just as an aside, to implement this, I would much rather monkeypatch
Object than Array. Otherwise it just happens again the next time I
have a class which begins with a vowel.

You also have the problem that classes which don't start with vowels
will inherit this. is_an? Person ??? And what about those who
use an before some /h\w+/i words? is_an? HistoricEvent, but not
is_an? House. It's probably best to get used to this. At least
other people's code won't grate on you, once you have. Let's face
it, this English language we got from the Romans, Saxons, ...,
Indians and more is very irregular. I'm glad Ruby isn't that
irregular.Hugh
 
L

Louis J Scoras

Just as an aside, to implement this, I would much rather monkeypatch
Object than Array. Otherwise it just happens again the next time I
have a class which begins with a vowel.

Want to be the most evil person in the world? EVER?

N.B.: Please don't do this =)

require 'enumerator'

objects = ObjectSpace.to_enum:)each_object)
classes = objects.select {|o| Class === o}

classes.each do |klass|
klass.instance_eval {
if [?A,?E,?I,?O,?U].include?(to_s[0])
alias_method :"is_an?", :"is_a?"
undef_method :"is_a?"
$stderr.puts "Was evil in Class: #{to_s}"
end
}
end
 
L

Louis J Scoras

Want to be the most evil person in the world? EVER?

N.B.: Please don't do this =)

require 'enumerator'

objects = ObjectSpace.to_enum:)each_object)
classes = objects.select {|o| Class === o}

classes.each do |klass|
klass.instance_eval {
if [?A,?E,?I,?O,?U].include?(to_s[0])
alias_method :"is_an?", :"is_a?"
undef_method :"is_a?"
$stderr.puts "Was evil in Class: #{to_s}"
end
}
end

Actually, I didn't even think that one all the way through. That
won't work thank goodness ;)
 
G

Giles Bowkett

Want to be the most evil person in the world? EVER?
N.B.: Please don't do this =)

require 'enumerator'

objects = ObjectSpace.to_enum:)each_object)
classes = objects.select {|o| Class === o}

classes.each do |klass|
klass.instance_eval {
if [?A,?E,?I,?O,?U].include?(to_s[0])
alias_method :"is_an?", :"is_a?"
undef_method :"is_a?"
$stderr.puts "Was evil in Class: #{to_s}"
end
}
end

Actually, I didn't even think that one all the way through. That
won't work thank goodness ;)

You know, this would make a pretty entertaining Ruby Quiz. Especially
if you also had to make sure that is_a? User and is_an? Udder had to
work properly as well.
 
D

Devin Mullins

Giles said:
You know, this would make a pretty entertaining Ruby Quiz. Especially
if you also had to make sure that is_a? User and is_an? Udder had to
work properly as well.

require 'rubygems'
require 'linguistics'
Linguistics.use :en, :installProxy => true
module Kernel
%w{a an}.each do |art|
define_method("is_#{art}?") do |mod|
raise NameError unless art == mod.name.a.split[0]
kind_of? mod
end
end
end
5.is_a? Object #=> NameError
5.is_an? Object #=> true
5.is_an? String #=> NameError
5.is_a? String #=> false

(Testing user/udder is left as an exercise to the reader.)

Devin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top