logo
down
shadow

Variable values based on class


Variable values based on class

By : German N
Date : November 22 2020, 07:01 PM
seems to work fine Why can't I change a scss variable based on a class? I want the variable to be green when in class dark-mode. , This is because of Variable Scoping.
code :
$background-color: #000;
$text-color: #fff;
$background-color: #fff;
$text-color: #000;
body {
    background: $background-color;
    color: $text-color;
}
.theme-dark {
    @import "theme-dark";
    @import "themed-page";
}

.theme-light {
    @import "theme-light";
    @import "themed-page";
}
$theme: 'default';

$theme-values: ( 
    'background-color': ( 
        'default': #eee,
        'light': #fff,
        'dark': #000
    ),
    'text-color': ( 
        'default': #333,
        'light': #000,
        'dark': #fff
    )
);

@function theme-value($key) {
    $map: map-get($theme-values, $key);
    @return map-get($map, $theme);
}
body {
    background: theme-value('background-color');
    color: theme-value('text-color');
}
.theme-dark {
    $theme: 'dark';
    @import "themed-page";
}

.theme-light {
    $theme: 'light';
    @import "themed-page";
}


Share : facebook icon twitter icon
Using array_merge to initialize static class variable in derived class based on parent class

Using array_merge to initialize static class variable in derived class based on parent class


By : Zack Salone
Date : March 29 2020, 07:55 AM
like below fixes the issue UPDATE: Solved! See below for what I ended up doing. everyone, I love SO! , try this:
code :
class Base {
  public static $array = array(
     'test1' => 'Hello',
  );
}

class Derived extends Base {
  public static $array = array(
     'test2' => 'Hello',
  );

  static function getArray(){
    return array_merge(self::$array, parent::$array);
  }
}
Derived::getArray();
Is it bad practice to declare instance variable values based on the name of the class?

Is it bad practice to declare instance variable values based on the name of the class?


By : Muhammad Tayyab
Date : March 29 2020, 07:55 AM
Hope this helps If @name is always intended to be equal to the class name, you don't need it – just use self.class.name or myObject.class.name directly, or define an accessor method which returns it if you don't want to use .class.name from the outside. Initializing it manually would be bad practice since you'd always have to remember to do it in every subclass and changes to subclass names would need to be replicated to the initialization.
If @name is not always going to equal the class name in every subclass, then personally I'd still provide a default implementation where it is initialized from self.class.name and let subclasses override it as necessary.
How do I get all pairs of values in a variable based on shared values in a different variable

How do I get all pairs of values in a variable based on shared values in a different variable


By : Swikan
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Here is a possible solution. Note that I modified your example df so A and C share both 162 and 64, and we have to make sure that this group does not occur twice in the output.
code :
df  = data.frame(scaffold = c("A", "A", "B", "B", "B", "C", "C", "D","A"), 
           geneID = c("162", "276", "64", "276", "281", "64", "162", "162","64"),stringsAsFactors = F)

y = split(df$scaffold,df$geneID)
unique(do.call(rbind,(lapply(y[which(sapply(y, length) > 1)],function(x){t(combn(sort(x),2))}))))
     [,1] [,2]
[1,] "A"  "C" 
[2,] "A"  "D" 
[3,] "C"  "D" 
[4,] "A"  "B" 
[5,] "B"  "C" 
NameSpacing: How to set class variable of inner class based on class variable of outer class?

NameSpacing: How to set class variable of inner class based on class variable of outer class?


By : Ricardo Ramos de Oli
Date : March 29 2020, 07:55 AM
I hope this helps you .
Is it possible to set class variables of inner class based on class variables of outer class?
code :
import os

# use a single leading underscore to mark those classes
# as "private" (=> not part of the module's API)
class _Fonts(object):
    def __init__(self, resource):
        self.font1 = os.path.join(resource.root, "font1.ttf")
        self.font2 = os.path.join(resource.root, "font2.ttf")

class _Resources(object):
    def __init__(self, src):
        self.root = os.path.join(rsc, "Ressources")
        self.Fonts = _Fonts(self)

# then instanciate it like any other class
src = "/path/to/source/folder"
Resources = _Resources(src)

print(Resources.Fonts.font1)
import os

class ResourcesMeta(type):
    def __init__(cls, name, bases, attrs):
        for name in attrs:
            obj = getattr(cls, name)
            if isinstance(obj, type) and issubclass(obj, SubResource):
                instance = obj(cls)
                setattr(cls, name, instance)


class SubResourceMeta(type):
    def __new__(meta, name, bases, attrs):
        if not bases:
            # handle the case of the SubResource base class
            return type.__new__(meta, name, bases, attrs)

        root = attrs.pop("root")
        cls = type.__new__(meta, name, bases, {})
        cls._root = root
        cls._attrs = attrs
        return cls

class SubResource(metaclass=SubResourceMeta):
    def __init__(self, parent):
        self.root = os.path.join(parent.root, self._root)
        for name, value in self._attrs.items():
            setattr(self, name, os.path.join(self.root, value))


class Resources(metaclass=ResourcesMeta):
    root = "/path/to/somewhere"

    class Fonts(SubResource):
        root = "fonts"
        font1 = "font1.ttf"
        font2 = "font2.ttf"

    class Images(SubResource):
        root = "images"
        logo = "logo"
        image1= "image1"
get self. values from class B to variables in function in class A, and then change the variable values without changing

get self. values from class B to variables in function in class A, and then change the variable values without changing


By : Rahul Shah
Date : March 29 2020, 07:55 AM
this will help I want to use values in class B(self.array_B) and assign them to variables(array_A) in class A while executing "step" function in class A. However, after I change the variable values(array_A) to be zeros in class A, the values of (self.array_B) are also changed to zeros which is very awkward. (self.array_B) should remain the same after I change the variable values in class A. Is there any way to solve this? , When assigning the list here:
code :
array_A = self.B.array_B
array_A = self.B.array_B.copy()
import copy
array_A = copy.deepcopy(self.B.array_B)
shadow
Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk