[#964] Bastion or SecurityManager for Ruby? — Clemens Hintze <clemens.hintze@...>

Hi,

15 messages 1999/12/10

[#989] a question about to_i — Friedrich Dominicus <Friedrich.Dominicus@...>

Sorry, I'm quite new to ruby. But I encounterd the following problem. If

17 messages 1999/12/19

[ruby-talk:01004] Re: a question about to_i

From: Friedrich Dominicus <Friedrich.Dominicus@...>
Date: 1999-12-20 11:50:19 UTC
List: ruby-talk #1004
GOTO Kentaro wrote:
> 
> Hi,
> 
> In message "[ruby-talk:01003] Re: a question about to_i"
>     on 99/12/20, Friedrich Dominicus <Friedrich.Dominicus@inka.de> writes:
> >But at least AFAIK there are some checker routines available in ctype.h
> >things like  isdigit, isascii, isalpha. I don't found s.th simular in
> >Ruby libs( sorry if I had overseen some points)
> 
> Excuse me. What does `s.th' stand for?
something.
> 
> >def sum_to(add_to,val_to_add):
> >       old_val = add_to
> >       try:
> >               add_to = add_to + int(val_to_add)
> >               assert add_to == old_val + int(val_to_add), "Adding failed"
> >       except ValueError:
> >               pass
> >       return add_to
> 
> >As mentioned before I'm to new to Ruby to know if that might work in
> >Ruby too.
> 
> Straightforward one:
> 
>   class AssertionError < StandardError; end
>   def assert(val = nil; msg = "")
>     if $DEBUG
>       val or raise AssertionError
>     end
>   end
> 
>   def sum_to(add_to, val_to_add)
>     old_val = add_to
>     begin
>       add_to = add_to + Integer(val_to_add)
>       assert add_to == old_val + Integer(val_to_add), "Adding failed"
>     rescue TypeError
>     end
>     add_to
>   end
> 
> But I don't see your aim of the assert statement. When isn't the
> equality satisfied?

This should be satisfied anytime. And is redundant but that are all
postconditions which assert is here. 

This might be  rest for the pre-implementation (before I used try and
except.

But you can of course argue the same way here:
remake (n: INTEGER) is
			-- Allocate space for at least `n' characters.
		require
			non_negative_size: n >= 0
		do
			make_area (n);
			count := 0
		ensure
			empty_string: count = 0;
			area_allocated: capacity >= n
		end;

When ever can the count = 0 not be true. But nevertheless it's very
useful to write such contracts down and maybe the contract was written
before the acutual implementation?

> 
> >> Let's discuss about it.
> >
> >What about tests can_be_integer, can_be_float or the like?
> 
> That is well acceptable but I don't need such a careful one as a
> built-in method.  Furthermore, deciding the proper behavior seems to
> be very difficult work. Someone might think can_be_integer('0L')
> should be true, and another might not, I guess.

Does ruby use L for signalling ints which are arbitrarily long? If not I
wouild think that 0L is not an Integer but anyway this is a difficult
field and I don't think that one or the other decisions is better or
worse.

> 
> We can easily define the suitable one as what we need like in
> [ruby-talk:0992] or [ruby-talk:0993].  Isn't it enough?

Yes that's enough. And that't what I've done. But I was thinking that
this is so useful that this might be included in some lib. Otherwise
this reminds me a bit of Scheme (you can write nearly anything there on
you own and because anyone did one can not easily port from on Scheme to
another, of course AFAIK there are not different implementations of Ruby
so this might be of no interest for Ruby users ;-)

Regards
Friedrich

In This Thread