44 Commits

Author SHA1 Message Date
Pete Kinnecom ebfdf8ae43 Fix Class inherited hook ordering
In CRuby the inherited method is invoked before Class.new yields to the
block.

An "already initialized error" exception is also removed since the
inherited method is now invoked before initialization and can set
instance variables on a class.
2026-05-07 15:51:30 +00:00
Paweł Świątkowski bdcd496bc2 Fix calling extended callback
The callback of extending module should be called, not of a singleton
class of an extended object.
2025-05-27 23:03:10 +02:00
Yukihiro "Matz" Matsumoto ecd2d8c11e wrap method arguments by parentheses as convention 2023-02-01 14:33:46 +09:00
Yukihiro "Matz" Matsumoto 01a21085f6 add a few regressions test from #2313
The code was contributed from Carson McDonald (@carsonmcdonald)
2021-06-03 16:47:04 +09:00
KOBAYASHI Shuji 8fa3995a1a Singleton class of frozen object should be frozen
Before this patch:

  p (class << Object.new.freeze; self end).frozen?                #=> false
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> false

After this patch / Ruby:

  p (class << Object.new.freeze; self end).frozen?                #=> true
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> true
2019-04-25 19:48:40 +09:00
KOBAYASHI Shuji 4720648137 Fix modiying class variable to frozen class/module 2019-04-24 21:05:44 +09:00
KOBAYASHI Shuji 729ab86d49 Fix missing assertion in test/t/class.rb 2019-03-02 18:55:02 +09:00
KOBAYASHI Shuji abbc501433 class/module expression with empty body should return nil
Before:

  p(class A end)          #=> A
  p(class << self; end)   #=> #<Class:#<Object:0x7fdc3880e420>>
  p(module B end)         #=> B

After/Ruby:

  p(class A end)          #=> nil
  p(class << self; end)   #=> nil
  p(module B end)         #=> nil
2019-01-28 21:29:55 +09:00
Yukihiro "Matz" Matsumoto cca19532c5 Remove Kernel#class_defined? which is not available in CRuby; #3829 2019-01-03 11:34:35 +09:00
Yukihiro "Matz" Matsumoto e471d37ca5 Separate meta-programming features to mruby-metaprog gem.
We assume meta-programming is less used in embedded environments.
We have moved following methods:

 * Kernel module
   global_variables, local_variables, singleton_class,
   instance_variables, instance_variables_defined?, instance_variable_get,
   instance_variable_set, methods, private_methods, public_methods,
   protected_methods, singleton_methods, define_singleton_methods

 * Module class
   class_variables, class_variables_defined?, class_variable_get,
   class_variable_set, remove_class_variable, included_modules,
   instance_methods, remove_method, method_removed, constants

 * Module class methods
   constants, nesting

Note:
Following meta-programming methods are kept in the core:

 * Module class
   alias_method, undef_method, ancestors, const_defined?, const_get,
   const_set, remove_const, method_defined?, define_method

 * Toplevel object
   define_method

`mruby-metaprog` gem is linked by default (specified in default.gembox).
When it is removed, it will save 40KB (stripped:8KB) on x86-64
environment last time I measured.
2018-08-30 22:30:36 +09:00
YAMAMOTO Masaya dcd5d0ffec Test for MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
Kouichi Nakanishi fd0f79ca67 Get constant of parent class even if child class is defined in signleton class; fix #3575 2017-04-06 23:31:34 +09:00
Kouichi Nakanishi 5efe77fede Modify class variable definition in singleton class; fix #3539 2017-03-30 16:29:47 +09:00
Yutaka HARA 3f83ec64a8 Add test for recently fixed bugs 2016-12-01 14:55:26 +09:00
Bouke van der Bijl 22f5504054 Fix segfault on remove_method with invalid argument
Reported by https://hackerone.com/jpenalbae
2016-11-24 10:13:47 -05:00
Kouhei Sutou ad492eb9f3 Fix class variable reference in module
Fix #3079
2016-01-11 00:34:15 +09:00
cremno 59ea323976 check if outer is a class or module
For modules this check didn't exist yet. Also call #inspect.
2015-05-29 14:58:53 +02:00
Kouhei Sutou e75e2083fd Fix a bug that class variable can't be referenced from class method
Class method defined in singleton class should be evaluated in class
context not singleton class context.

fix #2515
2014-08-09 15:06:17 +09:00
take_cheeze ec5b055694 Move direct superclass checking to test/t/superclass.rb. 2014-06-15 15:02:21 +09:00
ksss 1f3d7e939f Class.new add test case 2014-05-22 00:11:40 +09:00
h2so5 25045345c9 clone Class/Module rightly 2014-01-25 07:47:15 +09:00
Carson McDonald 0b8e342d59 When superclass isn't a class tests 2013-12-27 18:33:25 -05:00
Carson McDonald 9f212b9e81 More singleton tests 2013-12-27 18:32:11 -05:00
Carson McDonald 66747603d5 Add more testing for singletons 2013-12-25 12:16:53 -05:00
h2so5 12e00f9238 implement Class.new with block 2013-10-30 12:52:26 +09:00
Yukihiro "Matz" Matsumoto 3a6391c485 update test code to ensure return value from class statement 2013-10-25 13:24:50 +09:00
fleuria ba4a19dbe9 add a regression for #1544 2013-10-25 02:53:27 +08:00
Carson McDonald d55eb947f9 Test for Class#inherited 2013-08-13 22:27:25 -04:00
Carson McDonald e34bc72b89 Add test for Class.new(*args) 2013-08-13 22:11:14 -04:00
Jun Hiroe ff7e599491 I fix order of actual and expect test value in class.rb. 2013-08-02 20:54:08 +09:00
Yukihiro "Matz" Matsumoto 34cd70b1c5 Merge pull request #1279 from Bovi-Li/improve-tests
Improve Test Infrastructure (Part 1)
2013-06-14 04:30:52 -07:00
Daniel Bovensiepen c9caea64c8 Singleton raises TypeError on #new 2013-06-09 11:21:51 +08:00
Daniel Bovensiepen 968fc7a91c Improve Class tests 2013-06-09 05:04:04 +08:00
Daniel Bovensiepen 39b6d087c7 Improve alias tests 2013-06-09 04:04:19 +08:00
Daniel Bovensiepen 83d04a539e Improve undef tests 2013-06-09 03:51:44 +08:00
Carson McDonald 01c0373fac Add undef var test 2013-06-08 11:10:41 -04:00
Masaki Muranaka e129a4c8ef Add test cases. 2013-04-02 11:43:30 +09:00
Masamitsu MURASE d16659c7a5 Add test for undef and alias. 2013-01-20 17:44:28 +09:00
Masamitsu MURASE b71063b239 Modify test for Class.
* Rename some classes in test/t/class.rb to avoid name conflict.
* Add tests for mismatch fo superclass.
2012-07-29 14:21:12 +09:00
Daniel Bovensiepen 5612d195ec Improve Class#superclass to ISO 2012-06-03 23:29:40 +08:00
Yukihiro Matsumoto 7f243a9b53 resolve conflict in test/t/class.rb 2012-06-03 08:23:40 +09:00
Yukihiro Matsumoto df80b7835a Add Class#superclass; a patch made by @bovi; close #234 2012-06-03 08:20:48 +09:00
Daniel Bovensiepen 57bd8d49ec Add first test case for Class#new and prepare further feature tests for it 2012-06-03 01:50:10 +08:00
Daniel Bovensiepen 150b235fb6 Add Tests for all Exception classes, for false, true, Proc, Module, nil and Object 2012-05-25 14:01:14 +08:00