Convert string to int and use it on auto_click

auto_click is a gem pretty much used for manipulating keyboard/mouse via
ruby script.

The command below will take the mouse's cursor to the given co-ordinates
mouse_move(100,100)

if you do
mouse_move(0,0) the cursor will go to the top-left corner of the screen

Now I want to pass the co-ordinates via a variable
So far, I haven't found any smart way to do it.
Let's look what irb thinks of it below.

DL is deprecated, please use Fiddle
irb(main):001:0> require 'auto_click'
=> true
irb(main):002:0> coordinate = "100,100"
=> "100,100"
irb(main):003:0> mouse_move("#{coordinate}")
ArgumentError: wrong number of arguments (1 for 2)
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/auto_click-0.2.0/lib/auto_click
.rb:21:in `mouse_move'
        from (irb):3
        from C:/Ruby200/bin/irb:12:in `<main>'
irb(main):004:0>

···

--
Posted via http://www.ruby-forum.com/.

If I understand correctly, you need to convert the string "100,100" to
two ints to be passed to a method?
If that's the case, then:

coordinate = "100,100"
numbers = coordinate.split(",").map{|x| x.to_i}
mouse_move(*numbers)

should work.

Jesus.

···

On Wed, Feb 19, 2014 at 9:11 AM, cynic limbu <lists@ruby-forum.com> wrote:

auto_click is a gem pretty much used for manipulating keyboard/mouse via
ruby script.

The command below will take the mouse's cursor to the given co-ordinates
mouse_move(100,100)

if you do
mouse_move(0,0) the cursor will go to the top-left corner of the screen

Now I want to pass the co-ordinates via a variable
So far, I haven't found any smart way to do it.
Let's look what irb thinks of it below.

DL is deprecated, please use Fiddle
irb(main):001:0> require 'auto_click'
=> true
irb(main):002:0> coordinate = "100,100"
=> "100,100"
irb(main):003:0> mouse_move("#{coordinate}")
ArgumentError: wrong number of arguments (1 for 2)
        from
C:/Ruby200/lib/ruby/gems/2.0.0/gems/auto_click-0.2.0/lib/auto_click
.rb:21:in `mouse_move'
        from (irb):3
        from C:/Ruby200/bin/irb:12:in `<main>'
irb(main):004:0>

Jesus.

Thank you, God :stuck_out_tongue:

Although I found an alternative solution I shall try yours.

···

--
Posted via http://www.ruby-forum.com/\.