scope

MetaSearch Gem - Rails 3.0 working scope methods fail in Rails 3.2

本小妞迷上赌 提交于 2019-12-11 10:37:16
问题 MetaSearch's handy functions such as .not_in worked in Rails 3.0 & 3.1 inside of scope calls. I had to rewrite some scopes to be "plain Rails 3.2" without MetaSearch convenience even though MetaSearch works outside of scope. And it broke several of my apps & tools when I upgraded. Ideas? I am using MetaSearch everywhere. Even wrote a custom predicate. Still could be missing something obvious I hope. On Rails 3.2, working inside an engine for code separation. Didn't seem to matter when I tried

Instantiating a class and then pass it to setInterval

*爱你&永不变心* 提交于 2019-12-11 10:36:39
问题 I've a crazy problem. I'm instantiating an object from a class. Then I want to pass a function from this object to the setInterval function. The whole code block is executed with a keyDown event. Here's the code: function doKeyDown(e){ var instance = new Class(e.keyCode); setInterval(instance.functionToBeExecuded(), 200); } The strange thing is that it's getting executed once and then starts to loop an error which states (firebug): 27 SyntaxError: missing ] after element list [object

Why does a scala try block allow variables from the enclosing scope to be redefined?

和自甴很熟 提交于 2019-12-11 10:29:13
问题 Using Scala 2.10, the following compiles without an error. val test = 1 try { val test = 2 } Looking at the byte code generated, I see this: int test = 1; int test = 2; Isn't this strange? Or am I missing something obvious? 回答1: This has nothing to do with try . Variables can shadow each other in any block, and you can put blocks basically anywhere: val x = 0 if ({val x = 1; x*3}==0) { val x = 2; x + x + x } else x This makes code more portable: you can freely move blocks around without

How to iterate over instances of defined types in Puppet

妖精的绣舞 提交于 2019-12-11 10:21:19
问题 I want to iterate over all instances of defined types (ex. Apache::Vhost). However this loop only list my resources under the scope. <% scope.catalog.vertices.each do |resource| -%> <%# if resource.type == "Apache::Vhost" -%> #Include <%= resource.title %> <% end -%> 回答1: Walking the catalog durig at compile time ("catalog building") is a Bad Idea. If you really want this functionality, think about moving the iteration code to a custom provider that will generate the file content akin to what

Is there a way to change the values of variables in this language?

守給你的承諾、 提交于 2019-12-11 10:14:27
问题 I am writing a procedure in scheme and I am trying to manipulate the values of variables. I use the define function to give a value to a variable but I can't change the value. I would have used the let function but the variable change is only effective in the body of the let function. Are there other ways to manipulate variabes and be able to view the changes from anywhere in the procedure? Thanks 回答1: you can use set! set-car! set-cdr! after the variable has been defined 来源: https:/

How does global variables in JavaScript work? [duplicate]

扶醉桌前 提交于 2019-12-11 09:26:53
问题 This question already has answers here : Surprised that global variable has undefined value in JavaScript (6 answers) Closed 5 years ago . I m a newbie to javascript. I usually program in Java. I am confused by this following code snippet. <script> x = "foo"; function bar(p){ if (p){ document.writeln("x = " + x); } else { var x = "baz"; } } bar("baz"); </script> When I run the above code snipped its printing x = undefined Why does it print undefined, since x is a global variable it should

Passing a pointer to objects method safely to google.maps.event.addListener

会有一股神秘感。 提交于 2019-12-11 09:19:43
问题 When passing a method pointer to google.maps.event.addListener , google maps seems to overwrite it's this reference with an instance of google.maps.Map , therefore it renders it useless if the methods references any of its prototype memebers internally. The long story short, if I pass myObj.MyMethod as an event callback, at the time of its execution MyMethod.this reference will be an instance of google.maps.Map rather then myObj . Is there any way to safely pass a method pointer to

Rails / Kaminari - How to order a paginated array?

守給你的承諾、 提交于 2019-12-11 09:16:16
问题 I'm having a problem ordering an array that I've successfully paginated with Kaminari. In my controller I have: @things = @friend_things + @user_things @results = Kaminari.paginate_array(@things).page(params[:page]).per(20) I want to have the final @results array ordered by :created_at , but have had no luck getting ordering to work with the generic array wrapper that Kaminari provides. Is there a way to set the order in the Kaminari wrapper? Otherwise what would be the best way? Thanks. 回答1:

Javascript Array Scope Issue

不打扰是莪最后的温柔 提交于 2019-12-11 09:05:25
问题 SOLVED - This example code worked, so I compared it to the non-working I had and found a discrepancy. In my code, the one that did not work, when declaring the color array I forgot to add a "var" before it. m_color = []; m_color[0] = 255; m_color[1] = 255; m_color[2] = 255; m_color[3] = 255; instead of: var m_color = []; m_color[0] = 255; m_color[1] = 255; m_color[2] = 255; m_color[3] = 255; That's it. No error was generated and I guess it created it as a global array shared by all the

statically and dynamically scopes

廉价感情. 提交于 2019-12-11 08:24:50
问题 I'm working on this problem and I got the answers : Statically: 20, 16 Dynamically: 20, 100 is that correct? Consider the program below (in a Pascal like language). What is the output of the language is statically scoped? What is the output if the language is dynamically scoped? Program main; x: integer; procedure f1(z: integer) begin return z * x; end procedure f2(z: integer) int x; begin x = 2; return f1(z) * x; end begin /* main program */ x = 5; print f1(4); print f2(4); end 回答1: Why not