scope

Is there a way to call a private Class method from an instance in Ruby?

青春壹個敷衍的年華 提交于 2019-12-22 01:44:56
问题 Other than self.class.send :method, args... , of course. I'd like to make a rather complex method available at both the class and instance level without duplicating the code. UPDATE: @Jonathan Branam: that was my assumption, but I wanted to make sure nobody else had found a way around. Visibility in Ruby is very different from that in Java. You're also quite right that private doesn't work on class methods, though this will declare a private class method: class Foo class <<self private def

assign local variable from function in linux bash a new value

。_饼干妹妹 提交于 2019-12-22 01:44:54
问题 I have a linux bash script with a function: myfunctiona () { local MYVAR1="one" local MYVAR2="two" echo $MYVAR1 # The line beneath is the line in question! local MYVAR1=$MYVAR1$MYVAR2 } When I want to give the LOCAL variable MYVAR1 in the function myfunctiona a new value, do I have to write local MYVAR1=$MYVAR1$MYVAR2 or can I also write MYVAR1=$MYVAR1$MYVAR2 With the second line without "local" do I create a global variable with the same name? 回答1: Once you've defined a local variable you

Using a variable from outer scope in a sub called in foreach

♀尐吖头ヾ 提交于 2019-12-22 00:52:39
问题 I am using cygwin. What this script does is load the iphone pics that I have loaded into a directory on the desktop. It opens it up in image viewer, to let me take a look at the picture. system("cygstart $dirname/$oldfile") ; Then it gives me the option to rename the picture. It is throwing errors though, and not renaming the picture. Use of uninitialized value $oldfile in concatenation (.) or string at ./rename_image.pl line 29, <STDIN> line 6. oldfile is a global varaible, the functions

CodeIgniter, pass data from model to controller to use in view

≡放荡痞女 提交于 2019-12-21 21:39:27
问题 I want to pass data queried in my model to the controller, to do so I am using return $data. Then in the controller I use $this->load->view('my_view', $data); From my understanding var_dump($data); in the view should show me the results from the query... This is not the case. I am getting "undefined variable data" and NULL from the var_dump($data); . Here is my model: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Manage_accounts_model extends CI_Model {

Isolated execution context in JavaScript

元气小坏坏 提交于 2019-12-21 21:26:34
问题 I'm trying to execute a piece of code within an empty isolated execution context in JavaScript. In the below sample, I'm trying isolate isolated execution scope. What I want to do is to execute a function in context where no global variables are in. (function() { 'use strict'; var scope = Object.create(null); var isolated = function() { 'use strict'; console.log(document); // Trying to get undefined // but traces `document`. }; isolated.call(scope); })(); I thought it was simple to nullify

Coldfusion Local scope outside of a function?

霸气de小男生 提交于 2019-12-21 20:44:25
问题 What exactly is the local scope defined outside of a function? Consider the following code: <cfscript> local.madVar2 = "Local scope variable"; function madness() { var madVar = "madness variable"; madVar2 = "madness two variable"; writeOutput("local: <BR>"); writeDump(local); writeOutput("========================================= <BR>"); writeOutput("local.madVar2: <BR>"); writeDump(local.madVar2); writeOutput("<BR>========================================= <BR>"); writeOutput("madVar2: <BR>")

Why can you reflect and call a (not so) private method in Java and .Net

眉间皱痕 提交于 2019-12-21 17:52:02
问题 In both Java and C# it is possible to invoke a private method via reflection (as shown below). Why is this allowed? What are the ramifications of doing this? Should it be taken away in a future version of the language? Do other languages/platforms allow this?If I have this class in both Java and C# Here is the example public class Foo { private void say() { WriteToConsoleMethod("Hello reflected world"); } } where WriteToConsole() is language specific, then I can run the following to call the

PHP - Difference between 'use()' or 'global' to access a global variable in a closure?

左心房为你撑大大i 提交于 2019-12-21 15:44:28
问题 Is there any kind of performance or other difference between following two cases of accessing a global variable in a closure: Case 1: $closure = function() use ($global_variable) { // Use $global_variable to do something. } Case 2: $closure = function() { global $global_variable; // Use $global_variable to do something. } 回答1: There is an important difference between your two examples: $global_variable = 1; $closure = function() use ($global_variable) { return $global_variable; }; $closure2 =

angularjs: directive creates two child scope(not isolation scope)? and how to get scope of an element?

假装没事ソ 提交于 2019-12-21 15:25:12
问题 I am writing my angularjs directive with definition like: return { restrict: 'EA', link: link, scope: true, transclude: true, replace: true, controller: controller, template: '<div class="wizard">' + '<div ng-transclude></div>' + '</div>' }; I notice two scopes was created: < Scope (003) --- parent scope of directive < Scope (004) --- controller scope of directive which I think is child scope created by 'scope=true'. all my functions, properites defined in controller show up in this scope <

How do I loop vagrant provisioning in multi-machine environments to switch back and forth between machines?

江枫思渺然 提交于 2019-12-21 14:00:23
问题 I have a multi-machine Vagrantfile setting up a 5 node environment. I've been looking around to see what levels of control you have over the order of provisioning, but it's pretty limited: https://docs.vagrantup.com/v2/multi-machine/ I want to provision 5 nodes, then go back to the first node, and run other provisioning steps there. What I mean is that you have a Vagrantfile like this: Vagrant.configure('2') do |config| config.vm.provision some stuff config.vm.define 'node1' do |node1| node1