Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the major omissions in mruby compared to MRI?

Tags:

ruby

mruby

I'm quite interested in the mruby project, but have had no luck in finding a summarization of the major omissions in mruby compared to other, more complete Ruby implementations (most importantly, MRI).

The README in the project says that mruby implements "part of" the ISO standard for Ruby, but doesn't go into detail about which features are omitted.

Does anyone know of a list of such omissions, or is anyone familiar enough with the implementation to summarize?

like image 625
grumbler Avatar asked Sep 11 '13 04:09

grumbler


4 Answers

So I haven't read the source closely, but after having built mruby and run the interpreter a bit, I found that the following things were missing (by no means is this a complete list, nor do I know whether these are intentional omissions or just things that haven't been written yet):

  • backticks
  • eval
  • String#scan
  • (instance|module|class)_eval with String arguments
  • Module.constants
  • Regexp
  • Process
  • Bignum
  • IO, File, and Dir
  • Encoding
  • Thread and Mutex
  • Marshal

If anyone has a more complete list, or knows the details as to whether these bits are just not yet implemented or are intentionally omitted, I'd still be curious to know.

like image 72
grumbler Avatar answered Oct 04 '22 08:10

grumbler


An partial but up-to-date list of differences between Ruby MRI and MRuby can be found at https://github.com/mruby/mruby/blob/master/doc/limitations.md.

As of March 2020 these are the listed differences:

  • 1/2 gives Float(0.5) because mruby does not support Bignum.
  • Passing an Array to puts results in different output.
  • Kernel.raise without arguments does not raise the current exception within a rescue clause.
  • Fiber execution can't cross C function boundary
  • Array does not support instance variables
  • No method visibility (public/private/protected) is supported.
  • defined? is missing
  • Aliasing a global variable works in CRuby but is not part of the ISO standard.
  • An operator can't be overwritten by the user.
  • Kernel#binding is not supported.
  • Keyword arguments splats (def foo(a, b, **k)) are parsed in a different way.
  • Arguments cannot default to other destructed arguments (def foo(a, (b,c), d=b) is not valid).
  • Any redefinition of the nil? metho is ignored in conditional expressions.
like image 20
gioele Avatar answered Oct 04 '22 10:10

gioele


Have a look at the so called mrbgems (https://github.com/mruby/mruby/tree/master/mrbgems). Some of your missing features (i.e. RegExp, eval, File) are available as an additional GEM.

like image 25
Daniel Bovensiepen Avatar answered Oct 04 '22 08:10

Daniel Bovensiepen


I just run the simple code clip with mruby and got a different result from MRI.

class Fixnum
  def +(b)
    self * b
  end
end
puts 3+4 

mruby outputs 7 while MRI outputs 12

like image 36
Tim Wu Avatar answered Oct 04 '22 09:10

Tim Wu