Overwriting === method and how to call it [closed] - ruby

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is this a proper way to overwite the === method:
def ===(b)
self.venue === b.venue
print " new === !!!!"
end
And how do I call it on objects a and b who (as instances of the same class) both have the variable venue?
I tried puts a.===(b) but it doesn't work. (it says private method called for #<class1:0xsdfsd...>

Yes, it's proper way to overwrite === method.
You can call this method with:
a === b
or
a.===(b)
You have this error probably because you defined === method as private. Define it as a public method (above private keyword) and it should work.

The method should return a true or false, in this case you print something and the return value will always be nil. Try to change the order and use the print first.
Although you can call it using === it is much more common to use the operator in a case-statement or in the grep method.

Related

Gradle: task with variable inputs [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Is it a good idea for a task to get values from project properties or variables that can be changed. For example,
task mergeProperties {
def propertiesFile = new File(project.ext.file1)
def propertiesFile2 = new File(project.ext.file2)
def outputFile = new File(project.ext.file3)
inputs.files propertiesFile, propertiesFile2
outputs.file outputFile
doLast {
// merge properties
}
}
This method can be used to merge any two files and write to any file by changing property.ext properties. Is this a good idea? How UP_TO_DATE check works in this case?
Simple answer: No
As long as you do not provide an example use case or scenario that needs the behaviour described above, I think it is a bad idea to let property files or command line values decide on execution logic. This is what code (in your build.gradle) should be about.
Also, doLast (and doFirst) closures are for minor preparation and cleanup jobs, the main task actions should be defined by a #TaskAction in the custom task type definition:
class Merge extends DefaultTask {
#TaskAction
def merge() {
// merge properties
}
}
task mergeProperties(type: Merge) {
inputs.files 'myInputFile1', 'myInputFile2'
outputs.file 'myOutputFile'
}
Now, a special scenario (I can't imagine right now) could use project properties to define the input and output files.

Why do I get a "Value of type 'TableViewController' has no member 'place' ''? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am tying to download some data from parse (a string) and I get the error
"Value of type 'TableViewController' has no member 'place' on the line that says :
self.place.append(spotdetail.name!)
I have this as a global var :
var place = [""]
and this is my code in the ViewDidLoad:
let query = PFObject.query()
query!.findObjectsInBackgroundWithBlock ({ (objects, error) in
if let skateparks = objects {
for object in skateparks {
if let spotdetail = object as PFObject! {
self.place.append(spotdetail.name!)
self.tableView.reloadData()
}
}
}
print(place)
})
What can I change to make it work as I don't understand why it doesn't recognize the var place as it is in the same view controller (tableView)
thanks!
Everywhere in closure you should use self keyword for properties:
print(self.place)
As originaluser2 pointed out you are using a global variable so you do not need to user self.place. Also i'm not sure what you are subclassing in PFObject, but your func name is findObjectsInBackgroundWithBlock and you are reloading your table data there. Always keep in mind that you can only interact with the UI on the main thread. This will cause errors, so you can either pass back a callback, or do a GCD call to the main queue and then reload the data there.

How can i GET and POST global parameter? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can i GET and POST GLOBAL parameter?
example:
ViewBag.get = 2;
[HttpGet]/or/[HttpPost]
public ActionResult GetString(string? getnumber)
{
...////
}
You want to have global parameter in controller, but not in actions ?
I am not sure I understand you, but the best way to do that is using session. Something like that:
Set:
Session["Number"] = "2";
Get:
int number = (Session["Number"] != null) ? int.Parse(Session["Number"]) : -1;
I hope that helps, if not, specify your question :)

Creating a loop to generate mouseover functions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I've got a list of mouseOver functions, which for other pages will be much longer, so I'm looking for a way to generate the mouseOver functions in a loop.
Here's a small list of 5 functions in an example, by putting that in a single loop functions I should be able to understand how to expand it to more.
function mouseOver1()
{
document.pic.src ="img1.jpg"
}
function mouseOver2()
{
document.pic.src ="img2.jpg"
}
function mouseOver3()
{
document.pic.src ="img3.jpg"
}
function mouseOver4()
{
document.pic.src ="img4.jpg"
}
function mouseOver5()
{
document.pic.src ="img5.jpg"
}
Thanks for your help!!
(Moving discussion from comments)
You don't want to create five different methods. You want one method that can handle all of your situations.
function mouseOver(i) {
document.pic.src="img" + i + ".jpg";
}
And where before you would've called it like this:
mouseOver1();
You now call it like this:
mouseOver(1);
Does that make sense?

vb6 get data from Class module [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new in vb6 and not good at searching stuff. what is wrong with this code? I created form1 and inserted class module.
Private sub form_load()
call Jo.Display(txtdate.text)
end sub
in may Class module ClsJo
public function Display(txtdate as string)
txtdate = "123abc"
end function
The Display function has one parameter, txtdate, that is passed "by reference", which means that the function may change it's value. You are passing a value to that function, so I'm assuming you want the txtdate.Text property to contain the value "123abc" after the call.
However, this will not work as you have written it.
txtdate.Text is a property and properties are not really variables, they are kind of functions. You have "let" operator to set a property value and "get" operator to get the value of the property, but you don't have direct access to the actual variable that stores the value.
Therefore, when passed to the function, VB6 will get the value of the property, create a temporary variable from it and pass that temporary variable as the parameter to the function. The change in this temporary variable will never find it's way back to the txtdate.Text property.
To get the functionality that I think you want, you can do either one of these:
A. Create a variable yourself, pass that to the function and set the txtDate.Text property to the returned value. This would be my recommended method, because the function will have cleaner parameters. Like this:
Private Sub Form_Load()
Dim myText As String
myText = txtDate.Text
call Jo.Display(myText)
txtDate.Text = myText
End Sub
B: Pass the txtDate as parameter to the function, instead of the property, like this:
Public Sub Display(ByRef dateControl As Object)
dateControl.Text = "123abc"
End Function
Private Sub Form_Load()
Jo.Display txtDate
End Sub

Resources