methods

Why does “conformsToProtocol” not check for “required” method implementations?

非 Y 不嫁゛ 提交于 2019-12-10 14:49:27
问题 I am trying to enforce a "formal" @protocol , but cannot reliably test my classes/instances as to whether they ACTUALLY implement the protocol's "required" methods, vs. simply "declaring" that they conform to the protocol. A complete example of my quandary… #import <Foundation/Foundation.h> @protocol RequiredProtocol @required - (NSString*) mustImplement; @end @interface Cog : NSObject <RequiredProtocol> @end @implementation Cog @end @interface Sprocket : NSObject @end @implementation

Why x-editable-rails gem throwing an error: undefined method `xeditable?'?

北战南征 提交于 2019-12-10 14:38:32
问题 I installed the gem x-editable for rails: # x-editable gem 'x-editable-rails' I added the method xeditable? to the ActionController : # Add a helper method to your controllers to indicate if x-editable should be enabled. def xeditable? true # Or something like current_user.xeditable? end But still getting an error: ActionView::Template::Error (undefined method `xeditable?' for #<#<Class:0x007f9012e30f68>:0x007f9012ee9e78>): 14: 15: .panel-body 16: /a.doc_title.editable id='doc_title_12345'

Change variable passed in a method [duplicate]

て烟熏妆下的殇ゞ 提交于 2019-12-10 14:28:09
问题 This question already has answers here : 'pass parameter by reference' in Ruby? (6 answers) Closed 5 years ago . How can I change the contents of a variable using a method? Maybe I'm not saying this correctly. What is a way to get the reference to a variable like in C? Example: // main stuff int gorilla = 29; makeMeABanana(&gorilla); void makeMeABanana(int *gorilla) { } How can I do something like this in Ruby? 回答1: Recently on the ruby-talk mailing list, someone asked about writing a swap

How do I call a method from another class component in React.js

守給你的承諾、 提交于 2019-12-10 14:22:29
问题 So I have to class components: Class1: has a clickbutton Class2: has a method calling my api Basically, what I want is to call a method that sets and edits states inside one class from another class. But I keep failing. Example: Class1.js export class Class1 extends Component { render() { return ( <div onClick={must call Class2Method}></div> ) } } Class2.js export class Class2 extends Component { Class2Method(){ Here I call my API, I set & call states, ... } render { return ( <Class1 /> Here

JavaScript Chainable Method Delimma

泪湿孤枕 提交于 2019-12-10 14:11:42
问题 I have 2 methods that I'd like to use as chainable methods. Other methods may be chained to further modify text. left returns X characters from the left. right returns X characters from the right. Currently I can do this: var txt = "hello"; S$(txt).left(4).right(2).val //returns "ll" What I want to do is this. Basically I want to return the results after the last chained method without having to call the property. Is this possible? var txt = "hello"; S$(txt).left(4).right(2) //returns "ll"

`as.matrix` and `as.data.frame` S3 methods vs. S4 methods

社会主义新天地 提交于 2019-12-10 13:57:07
问题 I noticed that defining as.matrix or as.data.frame as S3 methods for an S4 class makes e.g. lm (formula, objS4) and prcomp (object) work out of the box. This doesn't work if they are defined as S4 methods. Why does it matter whether the methods are defined as S3 or S4 method? Example for as.data.frame : setClass ("exampleclass", representation (x = "data.frame")) object <- new ("exampleclass", x = iris) setMethod ("as.data.frame", signature="exampleclass", definition= function (x, ...) x@x )

Visual Studio 2013 Intellisense does not put enum type in a place of a parameter of method

跟風遠走 提交于 2019-12-10 13:55:26
问题 For example, I have the following code: namespace VS2013_EnumTypes { class Program { enum SomeEnum { One, Two } static void SomeMethod(SomeEnum someEnum) { //some code } static void Main(string[] args) { SomeMethod() } } } In Visual Studio 2010 and 2012 I can type name of the method SomeMethod and when I type parenthesis '(' then Visual Studio 2010 and 2012 offers me to select the type SomeEnum. But Visual Studio 2013 doesn't do this. It only add for me closing parenthesis and doesn't offer

Call an activity method from a BroadcastReceiver. Is it possible?

笑着哭i 提交于 2019-12-10 13:27:50
问题 I'm stuck developing an app because I need to call a method of my activity when a BroadcastReceiver is triggered. I want the BroadcastReceiver to detect when a network connection goes down and call a method of my activity which I've already written. I've been searching and I found that more people had asked this before but nobody got an answer about how to do it. I think that maybe android's API doesn't allow it. If it's impossible to call a method of my activity from the BroadcastReceiver

Eclipse: how to update a JUnit test file with newly added method in the source file?

偶尔善良 提交于 2019-12-10 12:49:50
问题 Using Eclipse (Helios), I could create a JUnit test file ClassATest.java of the source file ClassA.java by using New -> JUnit Test Case -> Class under test..., then choose all the methods of ClassA to be tested. If later we add some more methods to ClassA, how do we easily reflect this addition in ClassATest ? (No copy/paste plz). 回答1: One solution is to use MoreUnit With MoreUnit installed to Eclipse, one can right click onto the newly added method (and not yet unit tested), and choose

Getting a form to use :method => :delete (rails)

痴心易碎 提交于 2019-12-10 12:45:33
问题 I have a cart which contains many line_items. I'd like to have a "delete" button next to each line item that, upon clicked, removes the line_item from the cart. I know I can do this with a button_to method, but I'd like to use form_for because I'd like to change the attributes of the line_item's parent object at the same time (each line_item also belongs to a course, and I'd like to tell the course parent that it's no longer in the cart). Here's my code using form_for: <%= form_for(line_item,