scope

Scopes, lambda and rails 3

送分小仙女□ 提交于 2019-12-13 03:17:23
问题 having a play with scopes tonight in rails 3, and trying to get my head around what lambda does? What I am trying to achieve in this example is get a list of country names (:name) from my countries model which is associated with my recipe model. A recipe belongs_to country and a country has many recipes. I would like to order the recipes by amount of times they appear in a recipe, starting with the highest.. So i am trying this in my recipe model ( or should I do it within the country model?,

R function scope and parallelism

泪湿孤枕 提交于 2019-12-13 03:10:16
问题 Consider the following function definitions library(doParallel) f_print <- function(x) { print(x) } f_foreach <- function(l) { foreach (i=l) %do% { f_print(i) } } f_foreach_parallel <- function(l) { doParallel::registerDoParallel(1) foreach (i=l) %dopar% { f_print(i) } } Function use : > f_foreach(c(1,2)) [1] 1 [1] 2 [[1]] [1] 1 [[2]] [1] 2 > f_foreach_parallel(c(1,2)) Show Traceback Rerun with Debug Error in { : task 1 failed - "impossible de trouver la fonction "f_print"" [Error: could not

Incrementing a Variable from an Asynchronous Block in Objective-C

夙愿已清 提交于 2019-12-13 02:56:10
问题 I have run into a bit of a conundrum with a service I am working on in objective-c. The purpose of the service is to parse through a list of core-data entities and download a corresponding image file for each object. The original design of the service was choking my web-server with too many simultaneous download requests. To get around that, I moved the code responsible for executing the download request into a recursive method. The completion handler for each download request will call the

When to use self over $this?

社会主义新天地 提交于 2019-12-13 02:55:02
问题 In PHP 5, what is the difference between using self and $this ? When is each appropriate? 回答1: Short Answer Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members. Full Answer Here is an example of correct usage of $this and self for non-static and static member variables: <?php class X { private $non_static_member = 1; private static $static_member = 2; function _

Autofac: Reference from a SingleInstance'd type to a HttpRequestScoped

纵然是瞬间 提交于 2019-12-13 02:38:14
问题 I've got an application where a shared object needs a reference to a per-request object. Shared: Engine | Per Req: IExtensions() | Request If i try to inject the IExtensions directly into the constructor of Engine , even as Lazy(Of IExtension) , I get a "No scope matching [Request] is visible from the scope in which the instance was requested." exception when it tries to instantiate each IExtension . How can I create a HttpRequestScoped instance and then inject it into a shared instance?

How can Applescript objects be referenced before they are defined?

泪湿孤枕 提交于 2019-12-13 02:33:27
问题 Does anyone know why this applescript works? I do not understand why. The script generates three dialog boxes containing the same message: "Hi There". I have two questions: 1) How can j and k be set to reference i before i is defined? 2) Why does not r reference the i defined in test2? on test1() return get a reference to i end test on run set j to test1() set k to a reference to i set i to "Hi there" display dialog j display dialog k test2() end run on test2() set i to "now see here" set r

How can I derive classes from a base class that is encapsulated in a manager class?

核能气质少年 提交于 2019-12-13 02:21:48
问题 I have a ManagerClass that manages classes that derive from an abstract BaseClass. I need it so that only the ManageClass can access certain methods on the BaseClass. I also need certain methods to be accessible outside the scope of the ManagerClass. Since C# doesn't have friends, I'm encapsulating the BaseClass inside the ManagerClass. The problem: BaseClass is not accessible to derive from Making BaseClass public,means allowing DoStuff() and DoOtherStuff() to be called from outside the

C#- using a variable in an 'enclosing' local scope?

余生颓废 提交于 2019-12-13 02:17:32
问题 I am trying to add some new features to a C# application- in particular, trying to replicate some of its behavior, but inside a web browser, rather than in the application, as it currently is. I am trying to call a method that has been defined in the Browser.cs class from inside a method in the MainWindow.cs class. The method is defined in Browser.cs with: public partial class Browser : Form{ public Browser(){ ... } public void Browser_Load(object sender, EventArgs e){ webKitBrowser1.Navigate

Are there any context-sensitive code search tools?

天大地大妈咪最大 提交于 2019-12-13 02:15:28
问题 I have been getting very frustrated recently in dealing with a massive bulk of legacy code which I am trying to get familiar with. Say I try to search for a particular function call, I get loads of results that turn out to be completely irrelevant; some of them are easy to spot, eg a comment saying // Fixed functionality in foo() so don't need to handle this here any more But others are much harder to spot manually, because they turn out to be calls from other functions in modules that are

Adding events to elements inside loop - JScript/Closures

允我心安 提交于 2019-12-13 01:24:22
问题 I'm building a list of buttons and I want each one to trigger the addForm() function with the current members[member].id . But it happens that only the last button will fire the event. I know it has something to do with closures and as you can see I have adapted the function to use this pattern. What am I doing wrong? function displayConnections(connections) { /*(...)*/ for (var member in members) { connectionsDiv.innerHTML += "<p>" + members[member].firstName + " " + members[member].lastName