Making Ruby Stricter

J

John Andrews

To sell a Perl->Ruby transition in my company, I'd like to make
Ruby at least as strict as Perl. Our opinion is that Perl is
too loose and anything in Ruby that is looser than Perl will be
a strike against Ruby in some users' eyes. As an example, here
are three things I'd like to change:

(A) I want "to_i" to raise an exception if the conversion fails.

(B) I'd like most NilClass methods modified so that doing anything
except testing nil values for truth will raise exceptions.
For example, NilClass#to_i should raise an exception.

(C) I'd like to eliminate all the "synonym" methods from our
version of the language (this has nothing to do with being
stricter than Perl).

Here is code for (A):

class String
alias new_to_i to_i
def to_i
Kernel::Integer(self)
end
end

The implementation I have in mind is to add all of my code to a
module and then ask our users to include the "strict" module.

Here are my questions:

1) Has anyone else done something like this?

2) Doing changes like this will likely break existing methods in
Ruby classes and libraries that call the methods I've
modified, right? Is there a way around this?

3) Is there an implementation that avoids asking people to
include this "strict" module?

Thanks much,

JA
 

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
474,143
Messages
2,570,821
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top