Module: Kernel
- Defined in:
- lib/ludy/kernel/m.rb,
lib/ludy/kernel/id.rb,
lib/ludy/kernel/tap.rb,
lib/ludy/kernel/ergo.rb,
lib/ludy/kernel/defun.rb,
lib/ludy/kernel/if_else.rb,
lib/ludy/deprecated/aspect.rb,
lib/ludy/kernel/public_send.rb,
lib/ludy/kernel/singleton_method.rb,
lib/ludy/tasks/preprocess_cpp/attr_builder.rb,
lib/ludy/tasks/preprocess_cpp/header_guard.rb,
lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb
Instance Method Summary collapse
-
#accessor(type, *pros) ⇒ Object
just like attr_accessor for c++.
-
#alias_singleton_method(new_msg, old_msg) ⇒ Object
it simply alias singleton(instance) method.
-
#arguments(args_list) ⇒ Object
the arguments it passed.
- #cut(target, &block) ⇒ Object
-
#define_singleton_method(msg, &block) ⇒ Object
it would be defined if RUBY_VERSION < ‘1.9.0’, see rdoc in ruby 1.9.
-
#defun(name, *args, &fun) ⇒ Object
you can use defun for overloading(ad-hoc polymorphism), multi-method, pattern matching, and perhaps others?.
-
#else ⇒ Object
another else variant…
-
#ergo ⇒ Object
it simply return self, see NilClass#ergo.
-
#for_template_parameters_within(range, modifiers = ['volatile', 'const volatile']) ⇒ Object
forward template functions’ generator.
-
#forward_parameters(args_list) ⇒ Object
the parameters’ list.
-
#header_guard(random_suffix = nil, &block) ⇒ Object
C/C++ header guard generator, you shold provide the final #endif yourself, and you should provide PROJ name for header guard prefix.
-
#id(a = nil) ⇒ Object
id returns self.
-
#if ⇒ Object
another if variant…
-
#member_only(type, *pros) ⇒ Object
create only member, no writer(setter) and no reader(getter).
-
#public_send(msg, *args, &block) ⇒ Object
it would be defined if RUBY_VERSION < ‘1.9.0’, see rdoc in ruby 1.9.
-
#reader(type, *pros) ⇒ Object
just like attr_reader for c++.
-
#reader_only(type, *pros) ⇒ Object
create only reader(getter), no member and no writer(setter).
-
#tap {|_self| ... } ⇒ Object
it would be defined if RUBY_VERSION < ‘1.9.0’, see rdoc in ruby 1.9.
-
#template_parameters(args_list) ⇒ Object
parameter for template.
-
#writer(type, *pros) ⇒ Object
just like attr_writer for c++.
-
#writer_only(type, *pros) ⇒ Object
create only writer(setter), no member and no reader(getter).
Instance Method Details
#accessor(type, *pros) ⇒ Object
just like attr_accessor for c++
5 6 7 8 9 |
# File 'lib/ludy/tasks/preprocess_cpp/attr_builder.rb', line 5 def accessor type, *pros (reader_only type, *pros) + (writer_only type, *pros) + (member_only type, *pros) end |
#alias_singleton_method(new_msg, old_msg) ⇒ Object
it simply alias singleton(instance) method
10 11 12 |
# File 'lib/ludy/kernel/singleton_method.rb', line 10 def alias_singleton_method new_msg, old_msg self.class.__send__ :alias_method, new_msg, old_msg end |
#arguments(args_list) ⇒ Object
the arguments it passed
38 39 40 41 42 43 |
# File 'lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb', line 38 def arguments args_list size = args_list.count(',') + 1 Array.new(size).map_with_index{ |not_important, i| (i+10).to_s 36 }.join(', ') end |
#cut(target, &block) ⇒ Object
8 9 10 |
# File 'lib/ludy/deprecated/aspect.rb', line 8 def cut target, &block (class << target; self; end) end |
#define_singleton_method(msg, &block) ⇒ Object
it would be defined if RUBY_VERSION < ‘1.9.0’, see rdoc in ruby 1.9
5 6 7 |
# File 'lib/ludy/kernel/singleton_method.rb', line 5 def define_singleton_method msg, &block self.class.__send__ :define_method, msg, &block end |
#defun(name, *args, &fun) ⇒ Object
you can use defun for overloading(ad-hoc polymorphism), multi-method, pattern matching, and perhaps others?
7 8 9 |
# File 'lib/ludy/kernel/defun.rb', line 7 def defun name, *args, &fun Ludy::MessageDispatcher.create self, name, args, &fun end |
#else ⇒ Object
another else variant…
10 11 12 13 |
# File 'lib/ludy/kernel/if_else.rb', line 10 def else if self && !self.kind_of?(Ludy::Blackhole) then self else yield end end |
#ergo ⇒ Object
it simply return self, see NilClass#ergo
6 7 8 |
# File 'lib/ludy/kernel/ergo.rb', line 6 def ergo self end |
#for_template_parameters_within(range, modifiers = ['volatile', 'const volatile']) ⇒ Object
forward template functions’ generator
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb', line 9 def for_template_parameters_within range, modifiers = ['volatile', 'const volatile'] modifiers = ['', 'const'] + modifiers range.to_a.map_with_index{ |size, i| ([(["T"]*modifiers.size).zip( modifiers, ['&']*modifiers.size)]*size). map_with_index{ |args, arg_i| args.map{ |arg| # e.g., T0 const& a "#{arg.first}#{arg_i} #{arg.tail.join} #{(arg_i+10).to_s(36)}" } }.combos.map{ |arg| arg.kind_of?(Array) ? arg.join(', ') : arg } }.flatten.each{ |args_list| yield args_list } end |
#forward_parameters(args_list) ⇒ Object
the parameters’ list
33 34 35 |
# File 'lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb', line 33 def forward_parameters args_list args_list end |
#header_guard(random_suffix = nil, &block) ⇒ Object
C/C++ header guard generator, you shold provide the final #endif yourself, and you should provide PROJ name for header guard prefix
8 9 10 11 12 13 14 15 |
# File 'lib/ludy/tasks/preprocess_cpp/header_guard.rb', line 8 def header_guard random_suffix = nil, &block defined = "_#{Project.name.upcase}_#{@dir.upcase}_#{@class.upcase}_#{random_suffix.nil? ? '' : rand.to_s[2..-1]+'_'}" Ludy::erbout "#ifndef #{defined} #define #{defined}", block.binding block.call Ludy::erbout '#endif', block.binding end |
#id(a = nil) ⇒ Object
id returns self
5 |
# File 'lib/ludy/kernel/id.rb', line 5 def id a = nil; a.nil? ? self : a; end |
#if ⇒ Object
another if variant…
6 7 8 |
# File 'lib/ludy/kernel/if_else.rb', line 6 def if (yield if self).ergo end |
#member_only(type, *pros) ⇒ Object
create only member, no writer(setter) and no reader(getter)
44 45 46 47 |
# File 'lib/ludy/tasks/preprocess_cpp/attr_builder.rb', line 44 def member_only type, *pros result = "#{@prefix}private:\n" result << "#{@prefix}#{@indent}#{type} #{pros.map{|p|"#{p}_"}.join(", ")};\n" end |
#public_send(msg, *args, &block) ⇒ Object
it would be defined if RUBY_VERSION < ‘1.9.0’, see rdoc in ruby 1.9
5 6 7 8 9 10 11 |
# File 'lib/ludy/kernel/public_send.rb', line 5 def public_send msg, *args, &block if self.respond_to? msg self.__send__ msg, *args, &block else self.method_missing msg, *args, &block end end |
#reader(type, *pros) ⇒ Object
just like attr_reader for c++
12 13 14 15 |
# File 'lib/ludy/tasks/preprocess_cpp/attr_builder.rb', line 12 def reader type, *pros (reader_only type, *pros) + (member_only type, *pros) end |
#reader_only(type, *pros) ⇒ Object
create only reader(getter), no member and no writer(setter)
24 25 26 27 28 29 30 31 |
# File 'lib/ludy/tasks/preprocess_cpp/attr_builder.rb', line 24 def reader_only type, *pros result = "#{@prefix}public:\n" pros.each{ |p| # getter result << "#{@prefix}#{@indent}#{type} #{p}() const{ return #{p}_; }\n" } result end |
#tap {|_self| ... } ⇒ Object
it would be defined if RUBY_VERSION < ‘1.9.0’, see rdoc in ruby 1.9
5 6 7 8 |
# File 'lib/ludy/kernel/tap.rb', line 5 def tap yield self self end |
#template_parameters(args_list) ⇒ Object
parameter for template
25 26 27 28 29 30 |
# File 'lib/ludy/tasks/preprocess_cpp/template_forward_parameters.rb', line 25 def template_parameters args_list size = args_list.count(',') + 1 '<' + (['class T']*size).map_with_index{ |t, index| "#{t}#{index}" }.join(', ') + '>' end |
#writer(type, *pros) ⇒ Object
just like attr_writer for c++
18 19 20 21 |
# File 'lib/ludy/tasks/preprocess_cpp/attr_builder.rb', line 18 def writer type, *pros (writer_only type, *pros) + (member_only type, *pros) end |
#writer_only(type, *pros) ⇒ Object
create only writer(setter), no member and no reader(getter)
34 35 36 37 38 39 40 41 |
# File 'lib/ludy/tasks/preprocess_cpp/attr_builder.rb', line 34 def writer_only type, *pros result = "#{@prefix}public:\n" pros.each{ |p| # setter result << "#{@prefix}#{@indent}#{@class}& #{p}(#{type} const& new_#{p}){ #{p}_ = new_#{p}; return *this; }\n" } result end |