defined

How do I check if a class is defined?

孤街醉人 提交于 2019-12-17 22:11:40
问题 How do I turn a string into a class name, but only if that class already exists? If Amber is already a class, I can get from a string to the class via: Object.const_get("Amber") or (in Rails) "Amber".constantize But either of these will fail with NameError: uninitialized constant Amber if Amber is not already a class. My first thought is to use the defined? method, but it doesn't discriminate between classes that already exist and those that don't: >> defined?("Object".constantize) => "method

Java - parse user defined functions

孤人 提交于 2019-12-13 09:07:21
问题 I am working on a program, where I want users to define a simple functions like randomInt(0,10) or randomString(10) instead of static arguments. What is the best way to parse and process such functions ? I have not found any examples of such problem, the parser does not have to be ultra-efficient, it will not be called often, but mainly I want to focus on good code readability and scalability. Example of user input: "This is user randomString(5) and he is randomInt(18,60) years old!" Expected

Value error when no value error

≯℡__Kan透↙ 提交于 2019-12-13 04:29:32
问题 The following code triggers a value error: from pygame import * init() from random import * t = True f = False inventory = [] class block(object): def __init__(self,break_time,break_content,color): self.break_time = break_time self.break_content = break_content self.color = color def brek(self): inventory.append(self.break_content) end = block(1-0,None,(0,0,0)) gem = block(10,"agem",(0,0,100)) stone = block(3,"cobble",(100,100,100)) iron = block(5,"iron_ore",(25,50,100)) dirt = block(2,"dirt"

关于FireFox下event is not defined"的问题

一笑奈何 提交于 2019-12-12 11:37:56
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 编写MyShortKey.js过程中遇到一个问题,如下: 函数GetKeyCode2用于获取按键键值,如下: function GetKeyCode2() { var ex = event || window.event; //var keycode = e.which; var keycodes = ex.charCode || ex.keyCode; return keycodes; } 执行函数如下: window.onload = function() { document.onkeyup = function(){ //alert("按键事件执行了!"); //xGetKeyCode(event); document.getElementById("xkeycodesx").innerHTML = "已经载入!" + GetKeyCode2(); //document.getElementById("xkeycodesx").innerHTML = "已经载入!"; }; }; 以上代码在IE、OP、CH、SF等浏览器都正常运行,但在FF下却不运行,使用FF的FireBug插件得知错误信息为“ event is not defined ” 上网查找资料,得知:

How do I fix class template has already been defined?

青春壹個敷衍的年華 提交于 2019-12-11 18:58:46
问题 I am implementing ZipArchive library into my project, and I fought with it for over an hour getting it setup right to stop all the linker errors. But now I still have this left over and I am not sure of the best approach to fix it, could use some help. C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxtls_.h(199) : error C2953: 'CThreadLocal' : class template has already been defined c:\dev-mms\hl2sdk-ob-valve\public\tier0/threadtools.h(283) : see declaration of 'CThreadLocal'

javascript function says that is undefined

有些话、适合烂在心里 提交于 2019-12-11 17:55:20
问题 all I've written a function in order to calculate many things, so I've put the value of my vars in input of type hidden, so we have this code: <input type="hidden" id="p1" value="5000.00"> <input type="hidden" id="p2" value="5000.01"> <input type="hidden" id="p3" value="8000.00"> <input type="hidden" id="p4" value="8000.01"> <input type="hidden" id="t1" value="15.0"> <input type="hidden" id="t2" value="12.0"> <input type="hidden" id="t3" value="6.0"> <input type="hidden" id="versement" value=

Why a parameter is not defined, if I can dump it and it has a value in Coldfusion?

纵然是瞬间 提交于 2019-12-11 14:07:18
问题 Just a little clueless... using Coldfusion8, if I dump my session to file: <cfdump output="D:\ColdFusion8\logs\dump.txt" var="#Session#"> this includes: accounttyp: whatever I get the same result if I only dump this parameter: <cfdump output="D:\ColdFusion8\logs\dump.txt" var="#Session.accounttyp#"> Question: If it's defined and dump-able, how come checking isDefined like so: <cfdump output="D:\ColdFusion8\logs\dump.txt" var="#IsDefined(Session.accounttyp)#"> turns out to be NO ? If it's

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

How to judge whether a method has defined in a class?

倖福魔咒の 提交于 2019-12-10 03:05:50
问题 class C1 unless method_defined? :hello # Certainly, it's not correct. I am asking to find something to do this work. def_method(:hello) do puts 'Hi Everyone' end end end So, how to judge whether a method has defined or not? 回答1: The code you posted works just fine for checking whether the method is defined or not. Module#method_defined? is exactly the right choice. (There's also the variants Module#public_method_defined?, Module#protected_method_defined? and Module#private_method_defined?.)

User Defined Fields PHP Mysql

不问归期 提交于 2019-12-06 09:30:20
问题 I am currently building a small crm application. I need each user to be able to define their own custom fields. I am currently building this crm using php and mysql. Example: I have a "customer" table which has the standard fields: name, phone, address, email, etc. But i want to allow the user (unique session) to add fields that are custom to his/her business which are only accessible to him (not other users). I then want these custom fields to function just like all the other fields in the