[#390749] Why are there so many similar/identical methods in core classes — Kassym Dorsel <k.dorsel@...>

Let's look at the Array class and start with method aliases.

14 messages 2011/12/02

[#390755] Inverse Operation of Module#include — Su Zhang <su.comp.lang.ruby@...>

Hi list,

21 messages 2011/12/02
[#390759] Re: Inverse Operation of Module#include — Ryan Davis <ryand-ruby@...> 2011/12/02

[#390764] Re: Inverse Operation of Module#include — Isaac Sanders <isaacbfsanders@...> 2011/12/02

I would suggest an Adapter pattern use here. IF there is something that has

[#390876] black magical hash element vivification — Chad Perrin <code@...>

Ruby (1.9.3p0 to be precise, installed with RVM) is not behaving as I

12 messages 2011/12/05

[#390918] WEB SURVEY about Ruby Community — Intransition <transfire@...>

Did any one else get this survey request?

14 messages 2011/12/07

[#390976] Confusing results from string multiplication — Rob Marshall <robmarshall@...>

Hi,

19 messages 2011/12/08

[#391019] How can I do h["foo"] += "bar" if h["foo"] does not exist? — "Andrew S." <andrewinfosec@...>

Hi there,

13 messages 2011/12/09

[#391027] reading from file without end-of-lines — Janko Muzykant <umrzykus@...>

hi,

20 messages 2011/12/09
[#391028] Re: reading from file without end-of-lines — Gavin Sinclair <gsinclair@...> 2011/12/09

> i'm trying to read a few text values from single file:

[#391031] Re: reading from file without end-of-lines — Robert Klemme <shortcutter@...> 2011/12/09

On Fri, Dec 9, 2011 at 9:58 AM, Gavin Sinclair <gsinclair@gmail.com> wrote:

[#391042] Re: reading from file without end-of-lines — Gavin Sinclair <gsinclair@...> 2011/12/09

On Fri, Dec 9, 2011 at 8:18 PM, Robert Klemme

[#391135] I need advice on what to do next. — Nathan Kossaeth <system_freak_2004@...>

I am new to programming. I read the ebook "Learn to Program" by Chris

23 messages 2011/12/12

[#391216] perf optimization using profile results — Chuck Remes <cremes.devlist@...>

I need some help with optimizing a set of libraries that I use. They are ffi-rzmq, zmqmachine and rzmq_brokers (all up on github).

13 messages 2011/12/13
[#391218] Re: perf optimization using profile results — Chuck Remes <cremes.devlist@...> 2011/12/13

On Dec 13, 2011, at 9:57 AM, Chuck Remes wrote:

[#391234] Re: perf optimization using profile results — Charles Oliver Nutter <headius@...> 2011/12/14

A couple quick observations.

[#391238] Re: perf optimization using profile results — Chuck Remes <cremes.devlist@...> 2011/12/14

On Dec 13, 2011, at 7:03 PM, Charles Oliver Nutter wrote:

[#391324] ruby 1.9 threading performance goes non-linear — Joel VanderWerf <joelvanderwerf@...>

12 messages 2011/12/16
[#391325] Re: ruby 1.9 threading performance goes non-linear — Eric Wong <normalperson@...> 2011/12/16

Joel VanderWerf <joelvanderwerf@gmail.com> wrote:

[#391420] Accessing class instance variables from an instance? — "Shareef J." <shareef@...>

Hi there,

26 messages 2011/12/20
[#391454] Re: Accessing class instance variables from an instance? — Khat Harr <myphatproxy@...> 2011/12/21

Actually, now that I'm thinking about it the existing behavior sort of

[#391456] Re: Accessing class instance variables from an instance? — Josh Cheek <josh.cheek@...> 2011/12/21

On Tue, Dec 20, 2011 at 9:42 PM, Khat Harr <myphatproxy@hotmail.com> wrote:

[#391545] Kernel#exit raises an exception? — Khat Harr <myphatproxy@...>

While I was working on embedding an interpreter I wrote a function to

13 messages 2011/12/24

[#391618] rvmsh: An easy installer for RVM — Bryan Dunsmore <dunsmoreb@...>

I have recently begun work on a project called [rvmsh]

12 messages 2011/12/29

[#391783] Mailspam — Gunther Diemant <g.diemant@...>

Is there a way to stop this mailspam of Luca (Mail)?

12 messages 2011/12/29

[#391790] What’s the standard way of implementing #hash for value objects in Ruby? — Nikolai Weibull <now@...>

Hi!

23 messages 2011/12/29
[#391792] Re: What’s the standard way of implementing #hash for value objects in Ruby? — Gunther Diemant <g.diemant@...> 2011/12/29

I think you can't access instance variables from a class method, so

[#391793] Re: What’s the standard way of implementing #hash for value objects in Ruby? — Nikolai Weibull <now@...> 2011/12/29

On Thu, Dec 29, 2011 at 15:52, Gunther Diemant <g.diemant@gmx.net> wrote:

[#391811] Re: What’s the standard way of implementing #hash for value objects in Ruby? — Robert Klemme <shortcutter@...> 2011/12/29

On Thu, Dec 29, 2011 at 4:06 PM, Nikolai Weibull <now@bitwi.se> wrote:

[#391812] Re: What’s the standard way of implementing #hash for value objects in Ruby? — Nikolai Weibull <now@...> 2011/12/29

On Fri, Dec 30, 2011 at 00:26, Robert Klemme <shortcutter@googlemail.com> w=

[#391816] Re: What’s the standard way of implementing #hash for value objects in Ruby? — Josh Cheek <josh.cheek@...> 2011/12/30

On Thu, Dec 29, 2011 at 5:47 PM, Nikolai Weibull <now@bitwi.se> wrote:

[#391833] Re: What’s the standard way of implementing #hash for value objects in Ruby? — Robert Klemme <shortcutter@...> 2011/12/30

On Fri, Dec 30, 2011 at 12:47 AM, Nikolai Weibull <now@bitwi.se> wrote:

Re: round float to integer if whole number

From: Robert Klemme <shortcutter@...>
Date: 2011-12-15 08:14:13 UTC
List: ruby-talk #391278
On Wed, Dec 14, 2011 at 11:21 PM, Ronnie Aa <liquid98@gmail.com> wrote:
> Gunther Diemant wrote in post #1036785:
>> Possible tests:
>> ff.floor == ff
>> ff % 1 == 0
>>
>> If x is always an integer i would use the mod operator ( x % w == 0
>> ==> x/w integer)
>>
>> 2011/12/14 Ronnie Aa <liquid98@gmail.com>:
>
> thanxs Gunther!

That test does not work reliably:

irb(main):006:0> x = 1.0
=> 1.0
irb(main):007:0> x.class
=> Float
irb(main):008:0> 20.times do |i|
irb(main):009:1*   y = x + (10.0 ** -i)
irb(main):010:1>   printf "%4d %20.16f %s\n", i, y, y == y.floor
irb(main):011:1> end
   0   2.0000000000000000 true
   1   1.1000000000000001 false
   2   1.0100000000000000 false
   3   1.0009999999999999 false
   4   1.0001000000000000 false
   5   1.0000100000000001 false
   6   1.0000009999999999 false
   7   1.0000001000000001 false
   8   1.0000000099999999 false
   9   1.0000000010000001 false
  10   1.0000000001000000 false
  11   1.0000000000100000 false
  12   1.0000000000010001 false
  13   1.0000000000000999 false
  14   1.0000000000000100 false
  15   1.0000000000000011 false
  16   1.0000000000000000 true
  17   1.0000000000000000 true
  18   1.0000000000000000 true
  19   1.0000000000000000 true
=> 20

irb(main):024:0* x = BigDecimal.new "1.0"
=> #<BigDecimal:102e06c0,'0.1E1',9(18)>
irb(main):025:0> 20.times do |i|
irb(main):026:1*   y = x + (BigDecimal.new("10.0") ** -i)
irb(main):027:1>   printf "%4d %30.24f %s\n", i, y, y == y.floor
irb(main):028:1> end
   0     2.000000000000000000000000 true
   1     1.100000000000000088817842 false
   2     1.010000000000000008881784 false
   3     1.000999999999999889865876 false
   4     1.000099999999999988986588 false
   5     1.000010000000000065512040 false
   6     1.000000999999999917733362 false
   7     1.000000100000000058386718 false
   8     1.000000009999999939225290 false
   9     1.000000001000000082740371 false
  10     1.000000000100000008274037 false
  11     1.000000000010000000827404 false
  12     1.000000000001000088900582 false
  13     1.000000000000099920072216 false
  14     1.000000000000009992007222 false
  15     1.000000000000001110223025 false
  16     1.000000000000000000000000 false
  17     1.000000000000000000000000 false
  18     1.000000000000000000000000 false
  19     1.000000000000000000000000 false
=> 20

It is better to define "equality" differently for floating point
numbers.  There are a few common approaches:

1. Define a maximum difference that you accept, e.g.

irb(main):029:0> x = 1.0
=> 1.0
irb(main):030:0> 20.times do |i|
irb(main):031:1*   y = x + (10.0 ** -i)
irb(main):032:1>   printf "%4d %30.24f %s\n", i, y, (y - y.floor).abs < 1e-5
irb(main):033:1> end
   0     2.000000000000000000000000 true
   1     1.100000000000000088817842 false
   2     1.010000000000000008881784 false
   3     1.000999999999999889865876 false
   4     1.000099999999999988986588 false
   5     1.000010000000000065512040 false
   6     1.000000999999999917733362 true
   7     1.000000100000000058386718 true
   8     1.000000009999999939225290 true
   9     1.000000001000000082740371 true
  10     1.000000000100000008274037 true
  11     1.000000000010000000827404 true
  12     1.000000000001000088900582 true
  13     1.000000000000099920072216 true
  14     1.000000000000009992007222 true
  15     1.000000000000001110223025 true
  16     1.000000000000000000000000 true
  17     1.000000000000000000000000 true
  18     1.000000000000000000000000 true
  19     1.000000000000000000000000 true
=> 20

2. Define a maximum delta for the factor to 1

irb(main):034:0> 20.times do |i|
irb(main):035:1*   y = x + (10.0 ** -i)
irb(main):036:1>   printf "%4d %30.24f %s\n", i, y, ((y / y.floor) -
1).abs < 1e-5
irb(main):037:1> end
   0     2.000000000000000000000000 true
   1     1.100000000000000088817842 false
   2     1.010000000000000008881784 false
   3     1.000999999999999889865876 false
   4     1.000099999999999988986588 false
   5     1.000010000000000065512040 false
   6     1.000000999999999917733362 true
   7     1.000000100000000058386718 true
   8     1.000000009999999939225290 true
   9     1.000000001000000082740371 true
  10     1.000000000100000008274037 true
  11     1.000000000010000000827404 true
  12     1.000000000001000088900582 true
  13     1.000000000000099920072216 true
  14     1.000000000000009992007222 true
  15     1.000000000000001110223025 true
  16     1.000000000000000000000000 true
  17     1.000000000000000000000000 true
  18     1.000000000000000000000000 true
  19     1.000000000000000000000000 true
=> 20

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

In This Thread