global

ways to define a global method in ruby

一个人想着一个人 提交于 2020-01-01 03:09:31
问题 I'm writing a small gem, and I want to define a DSL-like method, pretty much the same as the desc and task methods in Rake . Rake defines them as private methods in the Rake::DSL module and then self.extend Rake::DSL to mix the module into the main object? (I'm a newbie and go ahead laugh if I'm wrong) what are the benefits by doing so? is it because making these methods private can prevent any other objects to use them (that is, to prevent something like some_obj.desc ) ? what if I define

JavaScript: global scope

僤鯓⒐⒋嵵緔 提交于 2019-12-31 10:49:51
问题 Nowdays, i create a .js file with a lot of functions and then I link it to my html pages. That's working but I want to know what's the best way (good practices) to insert js in my pages and avoid conflicts with scope... Thank you. 回答1: You could wrap them in an anonymous function like: (function(){ /* */ })(); However, if you need to re-use all of the javascript functions you've written elsewhere (in other scripts), you're better off creating a single global object on which they can be

JavaScript: global scope

此生再无相见时 提交于 2019-12-31 10:49:22
问题 Nowdays, i create a .js file with a lot of functions and then I link it to my html pages. That's working but I want to know what's the best way (good practices) to insert js in my pages and avoid conflicts with scope... Thank you. 回答1: You could wrap them in an anonymous function like: (function(){ /* */ })(); However, if you need to re-use all of the javascript functions you've written elsewhere (in other scripts), you're better off creating a single global object on which they can be

Making global var from inside a function in PHP

蹲街弑〆低调 提交于 2019-12-31 04:27:06
问题 I am trying to define dynamically variables. I am using a function for this, but I don't know how to define the new var as global (because it never created before the function). is that possible ? Thanks. edit ok, this is what I've built. is it that dangerous ? function extract_values($row) { foreach ($row as $key => $value){ global $$key; $$key = $value; } } and then I'm trying to make my life easier like that: $result = mysql_query("SELECT first_name, last_name, address FROM users ORDER BY

“Global variable” in Visual C#

≡放荡痞女 提交于 2019-12-31 04:04:16
问题 I have made the Graph class, and i want to simulate a distribution network. The Graph works 100%. But, i want to use that same struct/class in all my application! For example: I have Form1 that shows the simulation, but i want to insert Nodes (for example) but i want to do it in Form2! Since the data is always in the same class, i could make my Graph instance global but C# does not take global variables. So, how would i solve this? Any ideas? Thank you! 回答1: Give the forms a reference to the

Transferring int variable between activities Android

这一生的挚爱 提交于 2019-12-31 02:44:09
问题 I am making a quiz game. However, I need to add a score variable that can be modified. The way the game works is it uses a few different activities. How can I transmit this score and modify it throughout the activities. 回答1: Here's an example of passing an integer from one activity to another activity. Start ActivityA and pass it the int like this: Intent theIntent = new Intent(this, ActivityA.class); theIntent.putExtra("somename", intVariable); startActivity(theIntent); Get the integer from

Weird behaviour of $BASH_SOURCE

我的未来我决定 提交于 2019-12-31 02:20:15
问题 If you have foo.sh that declares a global function: myfunction(){ echo $*;} declare -fx myfunction And you source it: . foo.sh And then you call the global function from bar.sh: myfunction $BASH_SOURCE myfunction a b c myfunction $BASH_SOURCE The third call produces a blank line, unless bar.sh is being sourced. Any ideas how to bypass this problem? 回答1: Weird, this definitely looks like a bug. Possibly related to bash's shell function importing mechanism (when a shell function is found

PHP equivalent of ASP.NET Application/Cache objects

ⅰ亾dé卋堺 提交于 2019-12-30 18:27:19
问题 My Google-fu hasn't revealed what I'm looking for, so I'm putting this one out to the crowd. Coming from an ASP.NET development background, I'm used to having the Application and Cache collections available for me to stash rarely-modified but often-used resources (such as lookup rows from a database or the contents of static XML documents) in the memory of the web server, so I don't have to reload these often-used items during every request. Does PHP have an equivalent? I've read up briefly

PHP equivalent of ASP.NET Application/Cache objects

爷,独闯天下 提交于 2019-12-30 18:27:08
问题 My Google-fu hasn't revealed what I'm looking for, so I'm putting this one out to the crowd. Coming from an ASP.NET development background, I'm used to having the Application and Cache collections available for me to stash rarely-modified but often-used resources (such as lookup rows from a database or the contents of static XML documents) in the memory of the web server, so I don't have to reload these often-used items during every request. Does PHP have an equivalent? I've read up briefly

swift global constants: cannot use another constant for initialization

杀马特。学长 韩版系。学妹 提交于 2019-12-30 11:13:11
问题 Here is what I am trying to do: class ViewController: UIViewController { let screenRect: CGRect = UIScreen.mainScreen().bounds let screenWidth = screenRect.width; let screenHeight = screenRect.height; let screenX = screenRect.origin.x let screenY = screenRect.origin.y override func viewDidLoad() { ...and so on Swift allows me to declare screenRect . However, it does not allow me to declare any other constants using this. It shows me the error: 'ViewController.Type' does not have a member