From a58f5e08c63e5f73025e7db47740f7e18a604766 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 7 Jul 2023 02:34:17 +0100 Subject: [PATCH] meta functions defines accessors, readers and writers --- lib/voicemeeter/meta.rb | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lib/voicemeeter/meta.rb diff --git a/lib/voicemeeter/meta.rb b/lib/voicemeeter/meta.rb new file mode 100644 index 0000000..27208a5 --- /dev/null +++ b/lib/voicemeeter/meta.rb @@ -0,0 +1,67 @@ +module Voicemeeter + module Meta_Functions + # Accessor methods + def make_accessor_bool(*params) + params.each do |param| + define_singleton_method(param) { self.getter(param).to_i == 1 } + define_singleton_method("#{param}=") do |value| + self.setter(param, value && 1 || 0) + end + end + end + + def make_accessor_string(*params) + params.each do |param| + define_singleton_method(param) { self.getter(param, true) } + + define_singleton_method("#{param}=") do |value| + self.setter(param, value) + end + end + end + + def make_accessor_int(*params) + params.each do |param| + define_singleton_method("#{param}") do + return self.getter("#{param}").to_i + end + + define_singleton_method("#{param}=") do |value| + self.setter("#{param}", value) + end + end + end + + def make_accessor_float(*params) + params.each do |param| + define_singleton_method(param) { self.getter(param) } + + define_singleton_method("#{param}=") do |value| + self.setter(param, value) + end + end + end + + # reader methods + def make_reader_string(*params) + params.each do |param| + define_singleton_method(param) { self.getter(param, true) } + end + end + + def make_reader_int(*params) + params.each do |param| + define_singleton_method(param) { self.getter(param).to_i } + end + end + + # writer methods + def make_writer_string(*params) + params.each do |param| + define_singleton_method("#{param}=") do |value| + self.setter(param, value) + end + end + end + end +end