lib/sqlite_ext.rb in sqlite_ext-1.3.0 vs lib/sqlite_ext.rb in sqlite_ext-1.4.0
- old
+ new
@@ -68,12 +68,13 @@
end
end
end
# Registers most of the public module methods of Ruby's
- # `Math` module as well as `ceil` and `floor` to be used as
- # functions in SQL code executed # through subsequent new
+ # `Math` module as well as `ceil`, `floor`, `mod`, and
+ # `power` based on `Float` instance methods to be used as
+ # functions in SQL code executed through subsequent new
# instances of `SQLite3::Database`.
#
# The `Math.frexp` method is omitted becuse it returns an
# array, and there is no way to return an array from a SQL
# function in SQLite.
@@ -99,11 +100,19 @@
def register_ruby_math!
fn_methods = Math.public_methods - (Module.instance_methods << :frexp)
fn_methods.each do |m|
register_function m, Math.method(m)
end
- [:floor, :ceil].each do |m|
- register_function m, m.to_proc
+ register_function 'pi', ->(){ Math::PI }
+ register_function 'e', ->(){ Math::E }
+ [
+ [ :floor ],
+ [ :ceil ],
+ [ :modulo, :mod ],
+ [ :**, :power ]
+ ].each do |(*args)|
+ m, fn = args.first, args.last
+ register_function fn, m.to_proc
end
self.ruby_math_is_registered = true
end
# Registers a #create_function call to be invoked on every