Wednesday, July 23, 2008

Ruby: Floating point round off

my method of doing this as

def round(float, decimal_places) # By Jagan Reddy
exponent = decimal_places + 2
@float = float*(10**exponent)
@float = @float.round
@float = @float / (10.0**exponent)
end

In short we can also do this way
class Float
def round_to(i)
(self * 10**i).round.to_f / 10**i
end
end
value = 1328.3337
value.round_to(3)
=>1328.334

Friday, July 11, 2008

New AJAX google api rails plugin coming soon

Check this link for sample google ajax rails helper modules ...

http://www.strictlyuntyped.com/2008/06/using-google-ajax-libraries-api-with.html

Error can't dump anonymous class Class (apatana studio)

The system has a mainDocument model with different subclasses for different types of documents.
With the code below, if I attempt to create a Document, it works fine, but
if I attempt to use one of the subclasses, I get the error:

can't dump anonymous class Class

With an Application Trace of:

C:/Ruby/lib/ruby/1.8/yaml/rubytypes.rb:6:in `to_yaml'

When i started using aptana studio (radrails) 1.1.6 etc.. i got this error.

I searched all over the net for rails or ruby error list for this kind.. i could not find this problem any where.

But it solved when stopped apatana from dubugging mode to regular mode.

I dont know why but it works me fine afterwards.


please put your comments if u find any other soultion