1 # Limitations and Differences
3 The philosophy of mruby is to be a lightweight implementation of
4 the Ruby ISO standard. These two objectives are partially contradicting.
5 Ruby is an expressive language with complex implementation details which
6 are difficult to implement in a lightweight manner. To cope with this,
7 limitations to the "Ruby Compatibility" are defined.
9 This document is collecting these limitations.
13 This document does not contain a complete list of limitations.
14 Please help to improve it by submitting your findings.
17 ## ```1/2``` gives ```0.5```
19 Since mruby does not have ```Bignum```, bigger integers are represented
20 by ```Float``` numbers. To enhance interoperability between ```Fixnum```
21 and ```Float```, mruby provides ```Float#upto``` and other iterating
22 methods for the ```Float``` class. As a side effect, ```1/2``` gives ```0.5```
25 ## ```Array``` passed to ```puts```
27 Passing an Array to ```puts``` results in different output.
33 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
41 #### mruby [2.0.1 (2019-4-4)]
47 ## ```Kernel.raise``` in rescue clause
49 ```Kernel.raise``` without arguments does not raise the current exception within
60 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
62 ```ZeroDivisionError``` is raised.
64 #### mruby [2.0.1 (2019-4-4)]
66 No exception is raised.
68 ## Fiber execution can't cross C function boundary
70 mruby's ```Fiber``` is implemented in a similar way to Lua's co-routine. This
71 results in the consequence that you can't switch context within C functions.
72 Only exception is ```mrb_fiber_yield``` at return.
74 ## ```Array``` does not support instance variables
76 To reduce memory consumption ```Array``` does not support instance variables.
80 def initialize(str = nil)
88 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
92 #### mruby [2.0.1 (2019-4-4)]
94 ```ArgumentError``` is raised.
98 For simplicity reasons no method visibility (public/private/protected) is
104 def public_method; end
107 def private_method; end
111 p VisibleTest.new.respond_to?(:private_method, false)
112 p VisibleTest.new.respond_to?(:private_method, true)
115 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
122 #### mruby [2.0.1 (2019-4-4)]
131 The ```defined?``` keyword is considered too complex to be fully
132 implemented. It is recommended to use ```const_defined?``` and
133 other reflection methods instead.
139 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
145 #### mruby [2.0.1 (2019-4-4)]
147 ```NameError``` is raised.
149 ## ```alias``` on global variables
151 Aliasing a global variable works in CRuby but is not part
158 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
162 #### mruby [2.0.1 (2019-4-4)]
166 ## Operator modification
168 An operator can't be overwritten by the user.
179 #### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
181 ```ArgumentError``` is raised.
182 The re-defined ```+``` operator does not accept any arguments.
184 #### mruby [2.0.1 (2019-4-4)]
187 Behavior of the operator wasn't changed.
189 ## Kernel#binding is not supported
191 `Kernel#binding` method is not supported.
193 #### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)]
196 $ ruby -e 'puts Proc.new {}.binding'
197 #<Binding:0x00000e9deabb9950>
200 #### mruby [2.0.1 (2019-4-4)]
203 $ ./bin/mruby -e 'puts Proc.new {}.binding'
204 trace (most recent call last):
206 -e:1: undefined method 'binding' (NoMethodError)
211 mruby keyword arguments behave slightly different from CRuby 2.5
212 to make the behavior simpler and less confusing. Maybe in the
213 future, the simpler behavior will be adopted to CRuby as well.
215 #### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)]
218 $ ruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
219 [[{"a"=>1}], {:b=>2}]
222 #### mruby [mruby 2.0.1]
225 $ ./bin/mruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
226 trace (most recent call last):
228 -e:1: keyword argument hash with non symbol keys (ArgumentError)
231 ## Argument Destructuring
234 def m(a,(b,c),d); p [a,b,c,d]; end
235 m(1,[2,3],4) # => [1,2,3,4]
237 Destructured arguments (`b` and `c` in above example) cannot be accessed
238 from the default expression of optional arguments and keyword arguments,
239 since actual assignment is done after the evaluation of those default
249 CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`.