lib/tracksperanto/casts.rb in tracksperanto-2.9.8 vs lib/tracksperanto/casts.rb in tracksperanto-2.9.9
- old
+ new
@@ -27,6 +27,14 @@
attributes.each do | an_attr |
define_method(an_attr) { instance_variable_get("@#{an_attr}").to_s }
define_method("#{an_attr}=") { |to| instance_variable_set("@#{an_attr}", to.to_s) }
end
end
+
+ def cast_to_bool(*attributes)
+ attributes.each do | an_attr |
+ define_method(an_attr) { !!instance_variable_get("@#{an_attr}") }
+ define_method("#{an_attr}=") { |to| instance_variable_set("@#{an_attr}", !!to) }
+ end
+ end
+
end