scope

Bash Script Variable Scope Issue

旧街凉风 提交于 2019-12-23 04:54:29
问题 username="hello" password="3333" function login { # 1 - Username # 2 - Password match=0 cat LoginsMaintMenu.txt | while read line; do x=`echo $line | awk '{print $1}'` y=`echo $line | awk '{print $2}'` if [ "${x}" == "${1}" ] && [ "${y}" == "${2}" ]; then echo "match" match=1 echo $match break fi done echo $match return $match } echo $username $password login ${username} ${password} if [ $? -eq 0 ]; then echo "FAIL" else echo "success" fi output: hello 3333 match 1 0 FAIL THE PROBLEM: I don't

Ruby classes, include, and scope

£可爱£侵袭症+ 提交于 2019-12-23 03:23:11
问题 How does including a module affect scope? Specifically, in this example: module ModuleA class ClassA def initialize puts "test passed" end end end module ModuleB include ModuleA # test 1 C = ClassA.new class ClassB def initialize c = ClassA.new end end end # test 2 and 3 fail without this #include ModuleB module ModuleC # this doesn't help include ModuleB # test 2 ClassB.new # test 3 ModuleB::ClassB.new end test 1 works fine, but test 2 and test 3 fail without the commented-out import ModuleB

objective c xcode 4.0.2: subclass can't access superclass variables “was not declared in this scope”

落爺英雄遲暮 提交于 2019-12-23 03:09:07
问题 I have several classes that are subclasses of one Layer class.. for some reason one of the subclasses acts differently. this is a stripped down version: @interface Layer: CCLayer { GameScene* _scene; CCNode* _layerNode; } @end #import "Layer.h" @interface UILayer: Layer { } @end @implementation UILayer -(void) doStuff { [_layerNode addChild:[CCNode node]]; <---gives compile error: "_layerNode was not declared in this scope" [_scene playSound];<------gives compile error: "_scene was not

Why does one of my variables doesn't need declaration while the other one does?

人走茶凉 提交于 2019-12-23 02:52:58
问题 This code runs without errors. But in the function find_available_filenumber the variable render_folder isn't declared. So my question is why this doesn't produce an error? If I remove full_filename as a parameter, I get the error: UnboundLocalError: local variable 'full_filename' referenced before assignment. I don't understand why this doesn't also happen with render_folder , in my code example below: import bpy import os #Functions def find_available_filenumber(full_filename): file_number

Passing value into function and variable scope in JQuery

限于喜欢 提交于 2019-12-23 02:48:12
问题 Link to code example: http://jsfiddle.net/99Shr/ This code works for a given click handler, and $(this) takes on the particular class. I am attempting to take the code that is inside the click function and put it into it's own function. The reason I want to do this is because I would like to replace quantity-- with quantity++ depending on which click handler is called. The issue I am running into is that the variables when called in the function are undefined since $(this) is window. I am

xslt keep multiple variables in scope depending on a single test

两盒软妹~` 提交于 2019-12-23 02:38:06
问题 I have many variables and only two cases. My original approach goes out of scope : <xsl:choose> <xsl:when test='$something = 6'> <xsl:variable name="foo">x</xsl:variable> <!-- 50 other variables --> </xsl:when> <xsl:when test='$something = 7'> <xsl:variable name="foo">y</xsl:variable> <!-- 50 other variables --> </xsl:when> </xsl:choose> ie. later, with saxon, XPST0008: Variable x has not been declared (or its declaration is not in scope) I think it would work if I would choose inside an xsl

Extend JavaScript Class from separate file

♀尐吖头ヾ 提交于 2019-12-23 02:29:22
问题 I'm sorry to ask quite a dim question as I'm very new to OOP in JavaScript. I'm trying to use John Resig's Simple JavaScript Inheritance method, and ideally I'd like to store this within say utils.js , and then use it (using Class.extend ), throughout the range of script files that my project uses. Is this possible? I've noticed that if I create a subclass from within my utils.js file, I can then create a new instance of that class from a different script, so that makes me think it might be

How do I write a scope to search for attributes on a nested model?

喜欢而已 提交于 2019-12-23 02:04:49
问题 I have a Patient model that has_many :admissions. I want to create a scope for the patient model that will return all patients that are currently admitted. A patient is determined to be admitted if any of their admissions has a discharge_time of nil. I can do this easily enough in the app by iterating through the patients and checking each admission but it seems like I should be getting the database to do this. I haven't written a scope like this before. Any suggestions? (I'm using sqlite3 in

Scope of jQuery each() function?

痞子三分冷 提交于 2019-12-23 01:47:06
问题 I'm working with the jQuery ColorPicker widget - specifically exercising the ColorPickerSetColor function (just 'setColor' internally). Code excerpt: setColor: function(col) { if (typeof col == 'string') { col = HexToHSB(col); } else if (col.r != undefined && col.g != undefined && col.b != undefined) { col = RGBToHSB(col); } else if (col.h != undefined && col.s != undefined && col.b != undefined) { col = fixHSB(col); } else { return this; } return this.each(function(){ if ($(this).data(

Passing parameter to function in add.expr inside heatmap.2

被刻印的时光 ゝ 提交于 2019-12-23 01:41:30
问题 I'm generating clustering heatmap with heatmap.2 function (R gplots package). I'd like to add a vertical line(s) onto the image at variable location(s) using add.expr parameter. For example, xx=replicate(10, rnorm(10)) # some random matrix heatmap.2(xx, trace="none", add.expr=abline(v=c(3.5,6.5), lwd=3)) This works great. The problem is it doesn't work if I pass the lines location as a variable: linePosition = c(3.5,6.5) heatmap.2(..., add.expr=abline(v=linePosition, lwd=3)) It looks like