### Home Classes Methods

### In Files

- lib/facets/nullclass.rb
- lib/facets/yaml.rb
- lib/facets/basicobject.rb
- lib/facets/thread.rb

### Methods

- #null
- #safe_memo
- #sandbox
- #to_yamlfrag
- #yaml

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Random
- Random::ArrayExtensions
- Random::HashExtensions
- Random::IntegerExtensions
- Random::NumericExtensions
- Random::RangeExtensions
- Random::StringExtensions
- Random::StringExtensions::Self
- FileUtils
- FileUtils::DryRun
- FileUtils::NoWrite
- FileUtils::Verbose
- Digest
- Digest::Class
- Digest::Instance
- Multiton
- Multiton::Inclusive
- Multiton::MetaMethods
- URI
- URI::Hash
- URI::Kernel
- Argvector
- Argvector
- ERB
- ERB::OpenTemplate
- Enumerable
- Enumerable::Arguments
- GetoptLong
- GetoptLong::DSL
- Memoizable
- Memoizable::Copy
- Numeric
- Numeric::Multipliers
- Object
- Object::ArgVector
- Timer
- Timer::Dummy
- Array
- BasicObject
- CGI
- Cloneable
- Continuation
- Date
- DateTime
- Equitable
- File
- Find
- Hash
- Instantiable
- Integer
- Interval
- Kernel
- Math
- Module
- Net
- NilClass
- NullClass
- OpEsc
- OpenStruct
- Pathname
- Platform
- Range
- RbConfig
- Set
- Shellwords
- String
- StringScanner
- Time
- Tuple
- YAML
- Zlib

No matching classes.

# Kernel

### Public Instance Methods

null() click to toggle source

    # File lib/facets/nullclass.rb, line 27
    def null
      NullClass.new
    end

safe_memo(*args, &block) click to toggle source

Thead-safe instance-level memoization.

    class MemoExample
      attr_accessor :a
      def m
        safe_memo{ @a }
      end
    end

    ex = MemoExample.new

    ex.a = 10
    ex.m  #=> 10

    ex.a = 20
    ex.m  #=> 10

    # File lib/facets/thread.rb, line 36
    def safe_memo(*args, &block)
      if args.empty?
        args = block.binding.eval('[self, __method__]')
      end
      $MEMO_MUTEX.synchronize do
        if $MEMO.key?(args)
          $MEMO[args]
        else
          $MEMO[args] = block.call
        end
      end
    end

to_yamlfrag() click to toggle source

As with to_yaml but removes the header line (i.e. '---') to create a "YAML fragment".

CREDT: Thomas Sawyer

    # File lib/facets/yaml.rb, line 21
    def to_yamlfrag
      y = to_yaml
      y.sub!(/---\ */, '')
      y
    end

yaml(*args,&blk) click to toggle source

The Kernel method yaml is a shortcut to YAML::load.

    data = yaml %{
      a: 1
      b: 2
    }
    data #=> {"a"=>1, "b"=>2}

    # File lib/facets/yaml.rb, line 13
    def yaml(*args,&blk)
      YAML.load(*args,&blk)
    end

### Private Instance Methods

sandbox(rescueblock_or_default=nil) click to toggle source

CREDIT: Zucker

    # File lib/facets/thread.rb, line 79
    def sandbox(rescueblock_or_default=nil) #:yield:
      Thread.start do
        $SAFE = 4
        yield
      end.value
    rescue SecurityError => e
      if !rescueblock_or_default.nil?
        if rescueblock_or_default.is_a? Proc
          rescueblock_or_default.call e
        else
          rescueblock_or_default
        end
      else
        raise e
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.