Are There Any Ipython-Like Shells for Ruby or Rails

Are there any iPython-like shells for Ruby or Rails?

There is an irb tool to help autocomplete

require 'irb/completion'

ipython like interpreter for ruby

Even if you try pry it will give errors. Ubuntu does not get along well with ruby, you need few extra libraries. Following is what you can do:

sudo apt-get install libncurses5-dev libreadline5-dev

uninstall your current ruby version.
sudo apt-get install libreadline-dev
rvm install 1.9.3-p194 --with-readline-dir=/usr/include/readline

This shall fix it.

Are There Any Rails Modules or Classes Which Provide Frozen HTML Content Type Strings?

Creating a new module to facilitate simple storage and retrieval using the ActionPack Mime::Type system would work as follows:

# Build hash of type name to value, e.g., { xml: "application/xml" }
CONTENT_TYPES = {}.tap do |simple_content_types_hash|
# Get each registered Mime Type
Mime::EXTENSION_LOOKUP.each do |mime|
simple_content_type_hash[mime.first.to_sym] = mime.last.instance_variable_get("@string").freeze
end
end.freeze

Note: the above is untested, its just a generalization of what I am looking for. Thanks to @Fire-Dragon-DoL for the tip.

This could be added via an initializer, patched into an existing module, or into a new helper module.

Is sum or reduce(:+) better in Ruby/Rails? Are there considerations other than speed?

One way that the behaviour and result of using sum differ from inject &:+ is when you are summing floating point values.

If you add a large floating point value to a small one, often the result is just the same as the larger one:

> 99999999999999.98 + 0.001
=> 99999999999999.98

This can lead to errors when adding arrays of floats, as the smaller values are effectively lost, even if there is a lot of them.

For example:

> a = [99999999999999.98, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001]
=> [99999999999999.98, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001]
> a.inject(&:+)
=> 99999999999999.98

In this example, you could add 0.001 as often as you want, it would never change the value of the result.

Ruby’s implementation of sum uses the Kahan summation algorithm when summing floats to reduce this error:

> a.sum
=> 100000000000000.0

(Note the result here, you might be expecting something ending in .99 as there are 10 0.001 in the array. This is just normal floating point behaviour, perhaps I should have tried to find a better example. The important point is that the sum does increase as you add lots of small values, which doesn’t happen with inject &:+.)

Recommendations for a good C#/ .NET based lexical analyser

ANTLR has a C# target



Related Topics



Leave a reply



Submit