How do I contribute to Ruby?

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?

On 22/nov/06, at 23:28, Giles B. wrote:

I just HATE writing “is_a? Array” because it’s grammatically
incorrect.

What about String#include? isntead of includes? :stuck_out_tongue:

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?”

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.

Giles B. wrote:

I just HATE writing “is_a? Array” because it’s grammatically incorrect.

[].kind_of? Array

Giles B. wrote:

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

On 11/22/06, Giles B. [email protected] wrote:

No, I mean where to submit that change, having made it. Although I

There is a tracker for ruby at rubyforge, and there is a ruby-core
mailing list. See
http://www.ruby-lang.org/en/community/ruby-core/#patching-ruby

Giles B. wrote:

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).

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 V.

On 11/23/06, David V. [email protected] wrote:

Giles B. wrote:

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).

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.

[].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.

Hi –

On Thu, 23 Nov 2006, El Gato wrote:

(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

On Sat, 25 Nov 2006, Giles B. wrote:

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.


Giles B.
http://www.gilesgoatboy.org

    Hugh

On 11/24/06, Louis J Scoras [email protected] wrote:

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 :wink:

  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 :wink:

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

On 11/24/06, Giles B. [email protected] wrote:

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

Giles B. wrote:

You know, this would make a pretty entertaining Ruby Q… 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs