Ruby is currently the most flexible and agile programming language. It has special application methods and can bring a pleasant programming environment to programmers. Here we will learn the skills for Ruby to get the current class name.
- Using pp () to output two-dimensional arrays in Ruby
- Ruby on Rails directory files
- Ruby function pointer concepts
- Ruby Rmagick Installation Guide
- Ruby special syntax concepts
Example code for Ruby to obtain the current Class Name:
- Module Kernel
- Private
- Def this_method_name
- Caller [0] = ~ /'([^'] *)
'/And $1
- End
- End
- Class Foo
- Def test_method
- This_method_name
- End
- End
- Puts Foo. new. test_method
# =>Test_method
Caller [0] = ~ /'([^'] *) '/And $1, later, I found that caller [0] [/'([^'] *) '/, 1] is also written, so I checked the usage of caller in the reference manual, a little clearer;
Caller Returns [file name, row number, method name]
The preceding section describes how to obtain the current class name in Ruby.