• how to get access to the comparison passed

    From Mario Ruiz@21:1/5 to All on Mon Aug 29 07:49:31 2016
    If I have a method like this:

    def my_method(comp)
    #I know this is not working but to understand what I want
    puts comp.to_s
    return comp
    end


    my_method(4==6)
    # my_method will return false and print out 4==6

    b=7
    c=9
    life=false
    my_method(b<456)
    #my_method will return true and print out b<456

    my_method(c>=b)
    #my_method will return true and print out c>=b

    my_method(life)
    #my_method will return false and print out life

    is that possible?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Klemme@21:1/5 to Mario Ruiz on Mon Aug 29 21:42:38 2016
    On 29.08.2016 16:49, Mario Ruiz wrote:
    If I have a method like this:

    def my_method(comp)
    #I know this is not working but to understand what I want
    puts comp.to_s
    return comp
    end


    my_method(4==6)
    # my_method will return false and print out 4==6

    b=7
    c=9
    life=false
    my_method(b<456)
    #my_method will return true and print out b<456

    my_method(c>=b)
    #my_method will return true and print out c>=b

    my_method(life)
    #my_method will return false and print out life

    is that possible?

    Sort of, but eval is a security risk:

    def my_method(comp, binding)
    puts comp
    eval(comp, binding)
    end

    x = 10
    y = 20
    my_method "x > y", binding

    There is a gem which presumably lets you get rid of the second argument: https://rubygems.org/gems/binding_of_caller/

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mario Ruiz@21:1/5 to Robert Klemme on Tue Aug 30 05:48:58 2016
    Thanks!
    I got this one earlier... but I was trying to not be using eval and string

    On Monday, August 29, 2016 at 7:42:48 PM UTC, Robert Klemme wrote:
    On 29.08.2016 16:49, Mario Ruiz wrote:
    If I have a method like this:

    def my_method(comp)
    #I know this is not working but to understand what I want
    puts comp.to_s
    return comp
    end


    my_method(4==6)
    # my_method will return false and print out 4==6

    b=7
    c=9
    life=false
    my_method(b<456)
    #my_method will return true and print out b<456

    my_method(c>=b)
    #my_method will return true and print out c>=b

    my_method(life)
    #my_method will return false and print out life

    is that possible?

    Sort of, but eval is a security risk:

    def my_method(comp, binding)
    puts comp
    eval(comp, binding)
    end

    x = 10
    y = 20
    my_method "x > y", binding

    There is a gem which presumably lets you get rid of the second argument: https://rubygems.org/gems/binding_of_caller/

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)