Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7285

Re: how to get access to the comparison passed

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: how to get access to the comparison passed
Date Mon, 29 Aug 2016 21:42:38 +0200
Lines 48
Message-ID <e2jhhgF5cn2U1@mid.individual.net> (permalink)
References <fb2a2517-8e96-4f9d-bc28-e42722176626@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net eT5VWShqPndjwybUtZWEXQ2PcFtbtCcEoeS6c8z82JUAkkfHU=
Cancel-Lock sha1:12N03bh/mCcfOi2v1xPLaQIZxKk=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <fb2a2517-8e96-4f9d-bc28-e42722176626@googlegroups.com>
Xref csiph.com comp.lang.ruby:7285

Show key headers only | View raw


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/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

how to get access to the comparison passed Mario Ruiz <tcblues@gmail.com> - 2016-08-29 07:49 -0700
  Re: how to get access to the comparison passed Robert Klemme <shortcutter@googlemail.com> - 2016-08-29 21:42 +0200
    Re: how to get access to the comparison passed Mario Ruiz <tcblues@gmail.com> - 2016-08-30 05:48 -0700

csiph-web