On Fri, Feb 24, 2017 at 02:56:43PM +0100, Ancor Gonzalez Sosa wrote:

> For example, something as simple as this with the typical Ruby behavior
> (returning nil)
> 
> def compare_fs(partition1, partition2)
>   partition1.filesystem == partition2.filesystem
> end
> 
> With the current approach of rescuing exceptions or using the check
> method in advance (assuming that particular check method exist).
> 
> def compare_fs(partition1, partition2)
>   if partition1.has_filesystem
>      if partition2.has_filesystem
>        partition1.filesystem == partition2.filesystem
>      else
>        false
>      end
>    else
>      !partition2.has_filesystem
>    end
> end

That can easily be implemented in four lines.

But the use-case for the function is unclear to me. The
filesystems on two differnet partitions are always different
(sid, uuid, ...).

ciao Arvin



> The same problem of checking the value of several attributes can be
> generalized. Something like this would be quite common in Ruby (and is,
> in fact, the principle of many RSpec matchers that we cannot currently use).
> 
> def equivalent?(object1, object2, attributes = [])
>   attributes.each do |attr|
>     return false if object1.send(attr) != object2.send(attr)
>   end
>   true
> end
> 
> That will crash very easily and most ruby developers wouldn't have
> expected because disk.partition_table or partition.filesystem just look
> like attributes.

What looks like an attribute? How should they look so that ruby
developers do not expect them to be attributes?

ciao Arvin

-- 
Arvin Schnell, <[email protected]>
Senior Software Engineer, Research & Development
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 
(AG Nürnberg)
Maxfeldstraße 5
90409 Nürnberg
Germany
-- 
To unsubscribe, e-mail: [email protected]
To contact the owner, e-mail: [email protected]

Reply via email to