Is it possible to get rid of the eval statement below? The code below filters out all classes which are derived from type BaseClass. Afterwards those classes are instantiated and method 'hello' is called.
module MySpace
class BaseClass
def hello; print "\nhello world"; end
end
class A<BaseClass
def hello; super; print ",...
I know this question sounds rather vague so I will make it more clear with an example:
$var = 'bar';
$bar = new {$var}Class('var for __construct()'); //$bar = new barClass('var for __construct()');
This is what I want to do. How would you do it? I could off course use eval() like this:
$var = 'bar';
eval('$bar = new '.$var.'Class(\'v...
Duplicate of: How can I evaluate a C# expression dynamically?
See also: C# eval equivalent?
How to evaluate expression. Maybe like:
int a=1;
int b=3;
int c=Eval("a+b");
or
int c=int.parse("1+3*(2+3)");
This seems stupid to me. is it possible in c#?
...
I'm trying to figure out how to rescue syntax errors that come up when eval()ing code in Ruby 1.8.6.
I would expect the following Ruby code:
#!/usr/bin/ruby
good_str = "(1+1)"
bad_str = "(1+1" # syntax error: missing closing paren
begin
puts eval(good_str)
puts eval(bad_str)
rescue => exc
puts "RESCUED!"
end
to produ...
I have a javascript file that reads another file which may contain javascript fragments that need to be eval()-ed. The script fragments are supposed to conform to a strict subset of javascript that limits what they can do and which variables they can change, but I want to know if there is some way to enforce this by preventing the eval f...
I know, there's JSONP, which involves server cooperation to name-space the data.
What is bothering me is the fact that the content of script tag src is evaluated, but it's NOT available to read.
<script src="http://www.google.com"></script>
All we need to figure out is how to namespace the data, that's all.
Of course I tried...
How could I write Java code that is executed like javascript code used together with the eval function?
What I would like to achieve would be something like this:
System.execute ("String str = \"test\"; System.out.println(str);");
which would print the word 'test'. (10x dehmann )
A code sample would help a lot.
...
I've tried to parse the following json response with both the JQuery getJSON and ajax:
[{"iId":"1","heading":"Management Services","body":"<h1>Program Overview</h1><h1>January 29, 2009</h1>"}]
I've also tried it escaping the "/" characters like this:
[{"iId":"1","heading":"Management Services","body":"<h1>Program Overview <\/h1><h1>J...
I have been using eval feature of ruby many a times. But I have heard people saying evals are nasty. When asked, why and how, I could never get a convincing reason not to use it. Are they really nasty? If yes, in what way? What are possible "safer" options to eval?
...
An ajax request returns me a standard JSON array filled with my user's inputs. The input has been sanitized, and using the eval() function, I can easily create my javascript object and update my page...
So here's the problem. No matter how hard I try to sanitize the inputs, I'd rather not use the eval() function. I've checked google for...
As a perl programmer I can evaluate strings as code If I wished, Can I do the same in C#( with strings or some other object containing user input)?
What I want to accomplish is to create an object where its methods may be predefined in my source code or may be defined at run-time by the user by entering a string that represents C# code...
If I am evaluating a Python string using eval(), and have a class like:
class Foo(object):
a = 3
def bar(self, x): return x + a
What are the security risks if I do not trust the string? In particular:
Is eval(string, {"f": Foo()}, {}) unsafe? That is, can you reach os or sys or something unsafe from a Foo instance?
Is eval(s...
I'm working on a php project, and I want to run code that's fetched from a MySQL database. There's no chance of unsafe code being injected, so the only thing I'm worried about is performace. Should I use eval() so I can directly run the code, or parse it so that call_user_func() runs it instead?
For example, if the code I fetched was "m...
I'm playing around a bit with ActionScript. What I want is that I can display a mathematical function from a string.
E.g. in my working python script I do something like that:
formula = 'x**2 + 3*x'
for x in range( 0, 100 ):
y = eval( formula )
graph.display( x, y )
I want to port this to ActionScript, but it seems like ther...
Hi,
I'd like to do this (in REPL or anywhere)
(defn (symbol "print-string") [k] (println k))
and then be able to do
(print-string "lol")
Or, if there is any other way to create defn from custom strings in macroses, could you push me into the right direction please?
...
I've just started to play around with Eclipse GMF.
Has anyone used the framework?
Any good or bad experiences you made using it?
Any alternatives for graphical modeling you could suggest?
EDIT: What good examples are available?
...
This code works in irb:
irb(main):037:0> eval <<-EOS
irb(main):038:0" #{attribute} = "host"
irb(main):039:0" puts machine
irb(main):040:0" EOS
host
=> nil
irb(main):041:0> puts machine
host
=> nil
irb(main):042:0> puts attribute
machine
=> nil
irb(main):043:0>
however when I try to execute the same code as a ruby script I g...
I need to execute a method within an ItemTemplate in my DataList. How do I format the method in the page to work correctly with an Eval?
The method takes an int as a parameter.
<%# NumberOfEmplyeeOrders(Int32.Parse("EmployeeID"))%>
...
I'm trying to execute a number of functions using eval() and I need to create some kind of environment for them to run. It is said in docs that you can pass globals as a second parameter to eval(). But it seems to not work in my case. Here's the simpified example (i tried two approaches, declaring variable global and using globals(), bot...
There seems to be an odd discrepancy between the messages contained in Ruby Exceptions raised directly and raised from within evals. For instance, the following code:
def foo
raise "Help!"
end
puts "\nRescue foo"
begin
foo
rescue RuntimeError => e
puts e.message
end
puts "\nRescue eval 'foo'"
begin
eval "foo"
rescue RuntimeError =...