Why İ can't use join method in dart
example = join(dir.path, 'objectbox')
this gives error = The method 'join' isn't defined for the type '_MyHomePageState'.
Try correcting the name to the name of an existing method, or defining a method named 'join'.
Related
I have a variable handler whose value can be flight_gds, flight_commission etc.
There are classes in my application which has names like FlightGds, FlightCommission etc. under module FlightManager.
I want to execute the function of class based on the value of the handler.
The function name is same in all classes, only the class name is different which is dependent on
the handler.
For example:
If handler name is 'flight_gds', then the function is FlightManager::FlightGds.calculate()
I am trying something like this:
FlightManager::handler.camelize.calculate()
But I am getting undefined method handler error.
Is there any way to do this or I should go with if/else loop?
You should use constantize to get a class based on it's name in string:
"FlightManager::#{handler.camelize}".constantize.calculate())
I am doing a simple mapping and the compiler doesn't recognize the record's members.
The image shows the type OpeningHours itself is clearly ok, with all 3 properties showing:
But hovering over the marked property shows:
error FS0039: The field, constructor or member 'Day' is not defined.
Namespaces are all referenced and I even assign to the very same properties few lines below without any issue.
OpeningHours is a class, not a record. This is one way to create an instance of the class:
OpeningHours(day = oh.Day, opens = oh.Opens, closes = oh.Closes)
Based on the constructor and properties, it looks like OpeningHours is defined as a class, not a record. The record syntax can't be used with classes, so the solution is either to change OpeningHours to a record, or to instantiate it using its existing constructor.
public function setAlbumTable(AlbumTable $albumTable)
{
$this->albumTable = $albumTable;
return $this;
}
I am talking about first parameter ( it's not parameter btw) looks like datatype ? what is it ? constant ? I encounter this when trying to develop app in zend framework 2
This is PHP's type hinting. It means that the first parameter to this function - $albumTable - must be an instance of the AlbumTable class or a class that inherits from it.
class Car {}
class BlueCar extends Car {}
function drive_the_car(Car $car) {}
drive_the_car(42); // error, first parameter must be an instance of Car
drive_the_car(new stdClass()); // error
drive_the_car(new Car()); // works
drive_the_car(new BlueCar()); // works
The piece of code you're showing is an example of dependency injection via setter method. The setter is passed an instance of AlbumTable and assignes this instance to a class field.
Your method is passed ONLY ONE parameter: $albumTable.
The AlbumTable before the parameter is a type hint and makes sure that only a instance of AlbumTable or a deriving class can be passed to the setter.
It forces the actual parameter ($albumTable) to be an instance of AlbumTable class. PHP will give a fatal error if anything else is passed to the function.
This is useful so you don't have to check what type of variable/object you received in order to make use of it's functions and properties.
How do I pass a value to a dynamic method name that's called on a rails model?
#model.send(dynamic_method_name.to_sym,123)
This gives the error:
wrong number of arguments (1 for 0)
If I were to use the same method like this though:
#model.post_id = 123
then it works.
So there is a "setter" method for the method post_id (and therefore the dynamic method name).
How do I pass a value to this setter when the method is dynamic?
thanks!
You need to add the "=" to your dynamic_method_name. In ruby, :post_id is the name of the getter, and :post_id= is the name of the setter. The .to_sym isn't strictly necessary so you can do this:
#model.send("#{dynamic_method_name}=", 123)
I have a unit test class:
type [<TestFixture>] BetTests()=
[<Test>]
member x.HasGoodOddsTest() =
let ret = HasGoodOdds 10.0
Assert.IsFalse(ret, "Expected false");
and a static method defined outside of the class:
let HasGoodOdds odds = odds >= 20.0
but I'm getting a compiler error: "The value or constructor 'HasGoodOdds' is not defined."
What's the syntax to get outside of the scope of the class? Thanks!
Is HasGoodOdds defined above the BetTests class? Is it defined in the same file?
It needs to be defined above it (in a prior file, or above it in this file - generally you can't reference entities in F# until after they are defined), and if the BetTests class is not defined in the same module, you need to either use a qualified name (as #Vitaliy says) or use an 'open' declaration to bring the namespace/module into scope.
This method should be defined in a module. Use Namespace.ModuleName.Method convention